00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 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 rng 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 /** 00073 \brief Return a pointer to the gsl_rng object (deprecated) 00074 00075 Used in gsl_miser and gsl_anneal. 00076 */ 00077 gsl_rng *get_gsl_rng(); 00078 00079 /// Set the seed 00080 void set_seed(unsigned long int s) { 00081 seed=s; 00082 gsl_rng_set(gr,seed); 00083 } 00084 00085 /// Set the seed 00086 void clock_seed() { 00087 seed=time(NULL); 00088 gsl_rng_set(gr,seed); 00089 } 00090 protected: 00091 00092 #ifndef DOXYGENP 00093 00094 gsl_rnga(const gsl_rnga &); 00095 gsl_rnga& operator=(const gsl_rnga&); 00096 00097 #endif 00098 #ifndef DOXYGEN_INTERNAL 00099 00100 /// The GSL random number generator 00101 gsl_rng *gr; 00102 00103 /// The GSL random number generator type 00104 const gsl_rng_type *rng; 00105 00106 #endif 00107 00108 }; 00109 00110 #ifndef DOXYGENP 00111 } 00112 #endif 00113 00114 #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