35 #define TF_RNG_CC_VERSION \ 41 #include <gsl/gsl_rng.h> 55 Mstd(
std), Mmean(mean)
57 if (std::string(
type) ==
"default")
60 const gsl_rng_type* T=gsl_rng_default;
62 TFXX_assert(
MR!=NULL,
"gsl_rng_alloc(T) failed to initialize RNG");
66 const gsl_rng_type* T=NULL;
67 const gsl_rng_type **t, **t0;
68 t0 = gsl_rng_types_setup ();
70 for (t = t0; *t != 0; t++)
72 if (std::string((*t)->name)==std::string(
type)) { T=(*t); }
76 TFXX_assert(
MR!=NULL,
"gsl_rng_alloc(T) failed to initialize RNG");
78 this->
set(gsl_rng_default_seed);
99 {
return(this->
value()); }
114 { this->
set(time(0)); }
124 const gsl_rng_type **t, **t0;
126 t0 = gsl_rng_types_setup ();
128 for (t = t0; *t != 0; t++)
130 os << std::string((*t)->name) << std::endl;
140 const char* condition):
141 TBase(
"unkown RNG type requested", file, line, condition),
146 std::cerr <<
" Requested RNG type: " <<
Mtype << std::endl;
154 "The recommended random number generator type is \"ranlxd2\"\n" 157 "https://www.gnu.org/software/gsl/doc/html/index.html\n" 158 "https://www.gnu.org/software/gsl/doc/html/rng.html#random-number-generator-algorithms\n" 160 "The following generators are recommended for use in simulation. They have\n" 161 "extremely long periods, low correlation and pass most statistical tests.\n" 162 "For the most reliable source of uncorrelated numbers, the second-generation\n" 163 "RANLUX generators have the strongest proof of randomness.\n" 168 " These generators produce double precision output (48 bits) from the\n" 169 " RANLXS generator. The library provides two luxury levels ranlxd1 and\n" 170 " ranlxd2, in increasing order of strength.\n" 173 "gsl_rng_ranlux389\n" 175 " The ranlux generator is an implementation of the original algorithm\n" 176 " developed by Luscher. It uses a lagged-fibonacci-with-skipping\n" 177 " algorithm to produce “luxury random numbers”. It is a 24-bit\n" 178 " generator, originally designed for single-precision IEEE floating\n" 179 " point numbers. This implementation is based on integer arithmetic,\n" 180 " while the second-generation versions RANLXS and RANLXD described\n" 181 " above provide floating-point implementations which will be faster\n" 182 " on many platforms. The period of the generator is about 10^{171}.\n" 183 " The algorithm has mathematically proven properties and it can\n" 184 " provide truly decorrelated numbers at a known level of randomness.\n" 185 " The default level of decorrelation recommended by Luscher is\n" 186 " provided by gsl_rng_ranlux, while gsl_rng_ranlux389 gives the\n" 187 " highest level of randomness, with all 24 bits decorrelated. Both\n" 188 " types of generator use 24 words of state per generator.\n" 190 " For more information see,\n" 192 " * M. Luscher, “A portable high-quality random number generator for\n" 193 " lattice field theory calculations”, Computer Physics Communications,\n" 194 " 79 (1994) 100–110.\n" 195 " DOI: 10.1016/0010-4655(94)90232-1.\n" 196 " * F. James, “RANLUX: A Fortran implementation of the high-quality\n" 197 " pseudo-random number generator of Luscher”, Computer Physics\n" 198 " Communications, 79 (1994) 111–114\n" 199 " DOI: 10.1016/0010-4655(94)90233-X\n" RNGgaussian(const double &std=1., const double &mean=0., const char *type="default")
initialize random number generator
#define TFXX_assert(C, M)
Check an assertion and report by throwing an exception.
void set()
use time as seed value
UTException(const char *type, const char *file, const int &line, const char *condition)
Create with message, failed assertion, and code position.
double Mstd
store standard deviation and mean value
double value() const
returns a random number
unsigned long int seed() const
return last seed value
std::string type() const
return type of random number generator
const char * Mtype
pointer name string of requested RNG type
bool report_on_construct_is_true() const
static void rng_list_types(std::ostream &os)
print list of random number generators to stream.
exception class for RNG indicating request for unkown type
#define TFXX_Xassert(C, M, E)
Check an assertion and report by throwing an exception.
unsigned long int Mseed
memorize last seed value
static const char * comment_gsl_rng_ranlux
comment on GSL RNGs
double operator()() const
returns a random number
Base class for exceptions.
gsl_rng * MR
pointer to RNG
Namespace containing all code of library libtfxx.