class RED::Random

Class providing a Mersenne Twister-based pseudo-random numbers generator. More...

#include <REDRandom.h>

Inherits: RNG.

Public functions:

Random ( unsigned int iSeed = 24091975 )
virtual void *As ( const RED::CID & iCID )
virtual const void *As ( const RED::CID & iCID ) const
template< class T_As > const T_As *As ( ) const
template< class T_As > T_As *As ( )
virtual voidInit ( unsigned int iSeed )
virtual unsigned intRand32 ( )

Public static functions:

static RED::CIDGetClassID ( )

Private functions:

voidGenState ( )

Private variables:

unsigned int *_curstate
unsigned int *_endstate
unsigned int_state [624]

Detailed description:

Class providing a Mersenne Twister-based pseudo-random numbers generator.

As the built-in C/C++ pseudo-random numbers generator, this one has two methods: one for algorithm initialization (RED::Random::Init) and another one for getting 32bit numbers (RED::Random::Rand32). RED::Random::Max32 is the biggest number Rand32() can return.

This implementation is cross-platform and ensures users that the same numbers will be returned for a given seed on every machine run under any OS.

This generator is surely not the fastest one, but can be used as a reliable pseudo-random numbers generator for tasks which are not critic.

Functions documentation

public RED::Random::Random(unsigned intiSeed = 24091975)

Constructs a random numbers generator.

Parameters:

iSeed:seed used for initialization.

Reimplements: RED::RNG::GetClassID.

public virtual void * RED::Random::As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters:

iCID:Requested class.

Returns:

An object pointer of the given class on success, NULL otherwise.

Reimplements: RED::RNG::As.

public virtual const void * RED::Random::As(const RED::CID &iCID) const

Converts the object to an instance of the given type.

Parameters:

iCID:Requested class.

Returns:

An object pointer of the given class on success, NULL otherwise.

Reimplements: RED::RNG::As.

template< class T_As > public const T_As * RED::Random::As() const

Template version of the as const method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to a const instance of class T on success, NULL otherwise.

Reimplements: RED::RNG::As.

template< class T_As > public T_As * RED::Random::As()

Template version of the as method.

Simply set T to be the class you want to retrieve an interface to.

Returns:

A pointer to an instance of class T on success, NULL otherwise.

Reimplements: RED::RNG::As.

public virtual void RED::Random::Init(unsigned intiSeed)

Initializes a 32bit pseudo-random numbers generator.

Parameters:

iSeed:seed used for initialization.

Implements: RED::RNG::Init.

public virtual unsigned int RED::Random::Rand32()

Returns:

a 32bit pseudo-random number in the range [0, RED::Random::Max32-1].

Implements: RED::RNG::Rand32.

private void RED::Random::GenState()

RNG utility method.

Variables documentation

private unsigned int * RED::Random::_curstate

Pointer to the current state.

private unsigned int * RED::Random::_endstate

Pointer to the end state.

private unsigned int RED::Random::_state[624]