yat
0.20.3pre
|
Random Number Generator. More...
#include <yat/random/random.h>
Public Member Functions | |
unsigned long | max (void) const |
Returns the largest number that the random number generator can return. | |
unsigned long | min (void) const |
Returns the smallest number that the random number generator can return. | |
std::string | name (void) const |
Returns the name of the random number generator. | |
const gsl_rng * | rng (void) const |
void | seed (unsigned long s) const |
Set the seed s for the rng. More... | |
unsigned long | seed_from_devurandom (void) |
Seed the rng using the /dev/urandom device. More... | |
int | set_state (const RNG_state &) |
Set the state to state. More... | |
Static Public Member Functions | |
static RNG * | instance (void) |
Get an instance of the Random Number Generator. More... | |
Random Number Generator.
The RNG class is wrapper to the GSL random number generator (rng). In yat 0.8 (or older) this class provided a single global instance of the rng, and made sure there was only one point of access to the generator. Since version 0.9 this class provides one rng per thread in order to avoid collisions in multi-thread applications.
There are many different rng's available in GSL. RNG uses the default generator, unless the global variable gsl_rng_default
has been modified (see GSL Manual). Note, gsl_rng_default
should be changed before RNG creates its generator and safest way to achieve this is to modify gsl_rng_default
prior calling instance() the first time.
There is information about how to change seeding and generators at run time without recompilation using environment variables in the GSL Manual. RNG supports seeding at compile time if you don't want to bother about environment variables and GSL.
The class provides one generator per thread. The first generator created is seeded with gsl_rng_default_seed
and subsequent generators are seeded with gsl_rng_default_seed
+ 1, gsl_rng_default_seed
+ 2 etc, unless the seed has been modified with seed() or seed_from_devurandom().
|
static |
Get an instance of the Random Number Generator.
Get an instance of RNG. If a random number generator is not already created for current thread, the call will create a new generator of type gsl_rng_default
. If it is the first generator created it will be seeded with gsl_rng_default_seed
; otherwise created generator will be seeded with seed
+ n
, where seed
is the latest seed set (with seed() or seed_from_devurandom()) The seed may be changed with the seed or seed_from_devurandom member functions.
const gsl_rng* theplu::yat::random::RNG::rng | ( | void | ) | const |
Access underlying GSL random number generator speicific to current thread. Behaviour of returned generator is undefined outside current thread.
void theplu::yat::random::RNG::seed | ( | unsigned long | s | ) | const |
Set the seed s for the rng.
Set the seed s for the rng. If s is zero, a default value from the rng's original implementation is used (cf. GSL documentation).
This function will also effect generators created subsequently in other threads. The seed s is saved and subsequent generators will be created with seed s
+ 1, s
+ 2, etc.
unsigned long theplu::yat::random::RNG::seed_from_devurandom | ( | void | ) |
Seed the rng using the /dev/urandom device.
This function will also effect generators in other threads created subsequntly (see seed()).
int theplu::yat::random::RNG::set_state | ( | const RNG_state & | ) |
Set the state to state.
utility::GSL_error | on error |