#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. | |
unsigned long | seed_from_devurandom (void) |
Seed the rng using the /dev/urandom device. | |
int | set_state (const RNG_state &) |
Set the state to state. | |
Static Public Member Functions | |
static RNG * | instance (void) |
Get an instance of the random number generator. |
The RNG class is wrapper to the GSL random number generator (rng). This class provides a single global instance of the rng, and makes sure there is only one point of access to the generator.
There is information about how to change seeding and generators at run time without recompilation using environment variables in the GSL manual (Chapter on random number generators). RNG of course support seeding at compile time if you don't want to bother about environment variables and GSL.
There are many different rng's available in GSL. Currently only the default generator is implemented and no other one is choosable through the class interface. This means that you have to fall back to the use of environment variables as described in the GSL documentation, or be bold and request support for other rng's through the class interface.
Not all GSL functionality is implemented, we'll add functionality when needed and may do it when requested. Better yet, supply us with code and we will probably add it to the code (BUT remember to implement reasonable tests for your code and follow the coding style.)
The current implementation is NOT thread safe since the RNG is implemented as a singleton. However, the underlying GSL rng's support thread safety since each instance of GSL rng's keep track of their own state accordning to GSL documentation.
static RNG* theplu::yat::random::RNG::instance | ( | void | ) | [static] |
Get an instance of the random number generator.
Get an instance of the random number generator. If the random number generator is not already created, the call will create a new generator and use the default seed. The seed must be changed with the seed or seed_from_devurandom member functions.
const gsl_rng* theplu::yat::random::RNG::rng | ( | void | ) | const |
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).
unsigned long theplu::yat::random::RNG::seed_from_devurandom | ( | void | ) |
Seed the rng using the /dev/urandom device.
int theplu::yat::random::RNG::set_state | ( | const RNG_state & | ) |
Set the state to state.