00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 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 /** 00034 \brief Random number generator (GSL) 00035 00036 If \c seed is zero, or is not given, then the default seed 00037 specific to the particular random number generator is used. No 00038 virtual functions are used in this class or its parent, \ref 00039 rnga. This should be as fast as the original GSL version. 00040 00041 */ 00042 00043 class gsl_rnga : public rnga { 00044 public: 00045 00046 /** \brief Initialize the random number generator with type \c gtype 00047 and the default seed 00048 */ 00049 gsl_rnga(const gsl_rng_type *gtype=gsl_rng_mt19937); 00050 00051 /// Initialize the random number generator with \c seed 00052 gsl_rnga(unsigned long int seed, 00053 const gsl_rng_type *gtype=gsl_rng_mt19937); 00054 00055 ~gsl_rnga(); 00056 00057 /// Return rng type 00058 const gsl_rng_type *get_type() { return rng; } 00059 00060 /// Return a random number in \f$(0,1]\f$ 00061 double random() { 00062 return (gr->type->get_double)(gr->state); 00063 } 00064 00065 /// Return the maximum integer for random_int() 00066 unsigned long int get_max() { 00067 return gsl_rng_max(gr)-gsl_rng_min(gr); 00068 } 00069 00070 /// Return random integer in \f$[0,\mathrm{max}-1]\f$. 00071 unsigned long int random_int(unsigned long int n=0); 00072 00073 /** 00074 \brief Return a pointer to the gsl_rng object (deprecated) 00075 00076 Used in gsl_miser and gsl_anneal. 00077 */ 00078 gsl_rng *get_gsl_rng(); 00079 00080 protected: 00081 00082 #ifndef DOXYGENP 00083 00084 gsl_rnga(const gsl_rnga &); 00085 gsl_rnga& operator=(const gsl_rnga&); 00086 00087 #endif 00088 #ifndef DOXYGEN_INTERNAL 00089 00090 /// The GSL random number generator 00091 gsl_rng *gr; 00092 00093 /// The GSL random number generator type 00094 const gsl_rng_type *rng; 00095 00096 #endif 00097 00098 }; 00099 00100 #ifndef DOXYGENP 00101 } 00102 #endif 00103 00104 #endif