theplu::yat::random::RNG Class Reference

Random Number Generator. More...

#include <yat/random/random.h>

List of all members.

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 RNGinstance (void)
 Get an instance of the random number generator.


Detailed Description

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.

See also:
Design Patterns (the singleton and adapter pattern). GSL documentation.

Member Function 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.

Returns:
A pointer to the random number generator.
See also:
seed and seed_from_devurandom

const gsl_rng* theplu::yat::random::RNG::rng ( void   )  const

Returns:
const pointer to underlying GSL random generator.

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).

See also:
seed_from_devurandom

unsigned long theplu::yat::random::RNG::seed_from_devurandom ( void   ) 

Seed the rng using the /dev/urandom device.

Returns:
The seed acquired from /dev/urandom.

int theplu::yat::random::RNG::set_state ( const RNG_state  ) 

Set the state to state.

Returns:
0 on success, non-zero otherwise.
See also:
gsl_rng_memcpy


The documentation for this class was generated from the following file:

Generated on Tue Jan 18 02:21:18 2011 for yat by  doxygen 1.5.5