MIRA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | List of all members
RandomGenerator< Distribution, Engine > Class Template Reference

Template class to easily generate random generators using the boost::random distributions and generators. More...

#include <math/RandomGenerator.h>

Public Types

typedef Distribution::result_type result_type
 

Public Member Functions

 RandomGenerator ()
 Generates the random generator with default parameters for the random distribution. More...
 
 RandomGenerator (const Distribution &dist)
 Generates the random generator with the parameters provided by the given distribution. More...
 
 RandomGenerator (const RandomGenerator &other)
 Copy constructor that copies the distribution but initializes the random generator engine from the scratch, since engines cannot be copied. More...
 
RandomGeneratoroperator= (const Distribution &dist)
 Assigns the given distribution (respectively its parameters) to this random generator. More...
 
RandomGeneratoroperator= (const RandomGenerator &other)
 Assignment operator that copies the distribution but not the random generator engine, since engines cannot be copied. More...
 
result_type operator() ()
 Draws a sample from the random distribution. More...
 
void seed ()
 Seeds the random generator using the current system time. More...
 
void seed (uint32 value)
 Seeds the random generator with the given seed. More...
 
Distribution * operator-> ()
 Provides direct access to the underlying random distribution. More...
 
const Distribution * operator-> () const
 Provides direct access to the underlying random distribution. More...
 
Distribution & distribution ()
 Provides direct access to the underlying random distribution. More...
 
const Distribution & distribution () const
 Provides direct access to the underlying random distribution. More...
 
Engine & engine ()
 Provides direct access to the underlying random generator engine. More...
 
const Engine & engine () const
 Provides direct access to the underlying random generator engine. More...
 

Detailed Description

template<typename Distribution, typename Engine = boost::mt19937>
class mira::RandomGenerator< Distribution, Engine >

Template class to easily generate random generators using the boost::random distributions and generators.

The template takes two template parameters:

  1. A random distribution, e.g. NormalRandomDistribution or the boost random distributions
  2. The random generator engine, e.g. boost random engines, by default the Mersenne Twister (19937) is used.

Example:

RandomGenerator<boost::uniform_01<>> rnd;
for(int i=0; i<100; ++i)
double random_number=rnd();

There are also some predefined random generators:

Member Typedef Documentation

typedef Distribution::result_type result_type

Constructor & Destructor Documentation

RandomGenerator ( )
inline

Generates the random generator with default parameters for the random distribution.

The random generator is seeded with the default seed. Use the seed() method to set a different seed or to use the system time to generate a seed.

RandomGenerator ( const Distribution &  dist)
inline

Generates the random generator with the parameters provided by the given distribution.

The random generator is seeded with the default seed. Use the seed() method to set a different seed or to use the system time to generate a seed.

RandomGenerator ( const RandomGenerator< Distribution, Engine > &  other)
inline

Copy constructor that copies the distribution but initializes the random generator engine from the scratch, since engines cannot be copied.

Therfore, the copied generator has the same distribution including paramters etc, but produces a different random sequence unless it is called with the same seed.

Member Function Documentation

RandomGenerator& operator= ( const Distribution &  dist)
inline

Assigns the given distribution (respectively its parameters) to this random generator.

RandomGenerator& operator= ( const RandomGenerator< Distribution, Engine > &  other)
inline

Assignment operator that copies the distribution but not the random generator engine, since engines cannot be copied.

Therfore, the copied generator has the same distribution including paramters etc, but produces a different random sequence unless it is called with the same seed.

result_type operator() ( )
inline

Draws a sample from the random distribution.

void seed ( )
inline

Seeds the random generator using the current system time.

Hence, after calling this method, the random generator will generate different sequences of random numbers each time.

void seed ( uint32  value)
inline

Seeds the random generator with the given seed.

The random generator will produce the same sequence of random numbers if the same seed is used.

Distribution* operator-> ( )
inline

Provides direct access to the underlying random distribution.

const Distribution* operator-> ( ) const
inline

Provides direct access to the underlying random distribution.

Distribution& distribution ( )
inline

Provides direct access to the underlying random distribution.

const Distribution& distribution ( ) const
inline

Provides direct access to the underlying random distribution.

Engine& engine ( )
inline

Provides direct access to the underlying random generator engine.

const Engine& engine ( ) const
inline

Provides direct access to the underlying random generator engine.


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