Object-oriented Scientific Computing Library: Version 0.910
gsl_rnga.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_GSL_RNGA_H
00024 #define O2SCL_GSL_RNGA_H
00025 
00026 #include <gsl/gsl_rng.h>
00027 #include <o2scl/rnga.h>
00028 
00029 #ifndef DOXYGENP
00030 namespace o2scl {
00031 #endif
00032 
00033   /** \brief Random number generator (GSL)
00034 
00035       If \c seed is zero, or is not given, then the default seed
00036       specific to the particular random number generator is used.  No
00037       virtual functions are used in this class or its parent, \ref
00038       rnga. This should be as fast as the original GSL version.
00039 
00040       An interesting application of this class to generate an
00041       arbitrary distribution through a Markov chain Monte Carlo
00042       method is in \ref ex_markov_sect.
00043   */
00044 
00045   class gsl_rnga : public rnga {
00046   public:
00047 
00048     /** \brief Initialize the random number generator with type \c gtype 
00049         and the default seed 
00050     */
00051     gsl_rnga(const gsl_rng_type *gtype=gsl_rng_mt19937);
00052     
00053     /// Initialize the random number generator with \c seed 
00054     gsl_rnga(unsigned long int seed, 
00055              const gsl_rng_type *gtype=gsl_rng_mt19937);
00056     
00057     ~gsl_rnga();
00058     
00059     /// Return generator type
00060     const gsl_rng_type *get_type() { return rng; }
00061     
00062     /// Return a random number in \f$(0,1]\f$
00063     double random() {
00064       return (gr->type->get_double)(gr->state);
00065     }
00066 
00067     /// Return the maximum integer for random_int()
00068     unsigned long int get_max() {
00069       return gsl_rng_max(gr)-gsl_rng_min(gr);
00070     }
00071 
00072     /// Return random integer in \f$[0,\mathrm{max}-1]\f$.
00073     unsigned long int random_int(unsigned long int n=0);
00074     
00075     /// Set the seed
00076     void set_seed(unsigned long int s) { 
00077       seed=s;
00078       gsl_rng_set(gr,seed);
00079     }
00080 
00081     /// Set the seed
00082     void clock_seed() {
00083       seed=time(0);
00084       gsl_rng_set(gr,seed);
00085     }
00086 
00087   protected:
00088 
00089 #ifndef DOXYGENP
00090 
00091     gsl_rnga(const gsl_rnga &);
00092     gsl_rnga& operator=(const gsl_rnga&);
00093 
00094 #endif
00095 #ifndef DOXYGEN_INTERNAL
00096 
00097     /// The GSL random number generator
00098     gsl_rng *gr;
00099 
00100     /// The GSL random number generator type
00101     const gsl_rng_type *rng;
00102 
00103 #endif
00104   
00105   };
00106 
00107 #ifndef DOXYGENP
00108 }
00109 #endif
00110 
00111 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.