00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, 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 class gsl_rnga : public rnga { 00043 public: 00044 00045 /** \brief Initialize the random number generator with type \c gtype 00046 and the default seed 00047 */ 00048 gsl_rnga(const gsl_rng_type *gtype=gsl_rng_mt19937); 00049 00050 /// Initialize the random number generator with \c seed 00051 gsl_rnga(unsigned long int seed, 00052 const gsl_rng_type *gtype=gsl_rng_mt19937); 00053 00054 ~gsl_rnga(); 00055 00056 /// Return generator type 00057 const gsl_rng_type *get_type() { return rng; } 00058 00059 /// Return a random number in \f$(0,1]\f$ 00060 double random() { 00061 return (gr->type->get_double)(gr->state); 00062 } 00063 00064 /// Return the maximum integer for random_int() 00065 unsigned long int get_max() { 00066 return gsl_rng_max(gr)-gsl_rng_min(gr); 00067 } 00068 00069 /// Return random integer in \f$[0,\mathrm{max}-1]\f$. 00070 unsigned long int random_int(unsigned long int n=0); 00071 00072 /// Set the seed 00073 void set_seed(unsigned long int s) { 00074 seed=s; 00075 gsl_rng_set(gr,seed); 00076 } 00077 00078 /// Set the seed 00079 void clock_seed() { 00080 seed=time(NULL); 00081 gsl_rng_set(gr,seed); 00082 } 00083 protected: 00084 00085 #ifndef DOXYGENP 00086 00087 gsl_rnga(const gsl_rnga &); 00088 gsl_rnga& operator=(const gsl_rnga&); 00089 00090 #endif 00091 #ifndef DOXYGEN_INTERNAL 00092 00093 /// The GSL random number generator 00094 gsl_rng *gr; 00095 00096 /// The GSL random number generator type 00097 const gsl_rng_type *rng; 00098 00099 #endif 00100 00101 }; 00102 00103 #ifndef DOXYGENP 00104 } 00105 #endif 00106 00107 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page