MTRand Class Reference

Inheritance diagram for MTRand:

IntegerRandom RealRandom BernoulliRandom DiscreteUniformRandom ExponentialRandom NormalRandom UniformRandom UniformRandomSimple List of all members.

Detailed Description

Base class for random number generators.

This class is the base for all of the (pseudo) random number generators. It is based closely on MersenneTwister.h, v0.6, 14 February 2001, written by Richard J. Wagner. It has been modified and substantially trimmed down.

Author:
Richard J. Wagner (original code)

Bill Smart

Date:
November 2001
Version:
1.0

Definition at line 52 of file Random.H.

Public Member Functions

 MTRand (const unsigned long &oneSeed)
void setSeed (unsigned long seed)
 Set the random number seed.
void randomize ()
 Set the random number seed using a number generated from /dev/urandom.
Moments of the random variable
virtual double mean () const=0
virtual double variance () const=0
virtual double stdDev () const=0

Protected Member Functions

double rand ()
uint32 randInt ()
uint32 randInt (const uint32 &n)

Private Types

enum  { N = 624, M = 397, MAGIC = 0x9908b0dfU }
typedef unsigned long uint32

Private Member Functions

void reload ()
uint32 hiBit (const uint32 &u) const
uint32 loBit (const uint32 &u) const
uint32 loBits (const uint32 &u) const
uint32 mixBits (const uint32 &u, const uint32 &v) const
uint32 twist (const uint32 &m, const uint32 &s0, const uint32 &s1) const
 MTRand (const MTRand &mtrand)
MTRandoperator= (const MTRand &mtrand)

Private Attributes

uint32 state [N]
uint32pNext
int left


Member Typedef Documentation

typedef unsigned long uint32 [private]

Definition at line 77 of file Random.H.


Member Enumeration Documentation

anonymous enum [private]

Enumerator:
N 
M 
MAGIC 

Definition at line 93 of file Random.H.


Constructor & Destructor Documentation

MTRand ( const unsigned long &  oneSeed  )  [inline]

This allocates the class and sets the random number seed.

Parameters:
oneSeed Random number seed. Do not set this to zero.

Definition at line 57 of file Random.H.

References setSeed().

MTRand ( const MTRand mtrand  )  [private]


Member Function Documentation

void setSeed ( unsigned long  seed  )  [inline]

Set the random number seed.

Parameters:
seed Random number seed.

Definition at line 612 of file Random.H.

References N, reload(), and state.

Referenced by MTRand(), and randomize().

void randomize (  )  [inline]

Set the random number seed using a number generated from /dev/urandom.

Definition at line 624 of file Random.H.

References setSeed().

virtual double mean (  )  const [pure virtual]

Returns:
The mean of the random variable.

Implemented in RealRandom, IntegerRandom, UniformRandomSimple, UniformRandom, NormalRandom, ExponentialRandom, DiscreteUniformRandom, and BernoulliRandom.

virtual double variance (  )  const [pure virtual]

Returns:
The variance of the random variable.

Implemented in RealRandom, IntegerRandom, UniformRandomSimple, UniformRandom, NormalRandom, ExponentialRandom, DiscreteUniformRandom, and BernoulliRandom.

virtual double stdDev (  )  const [pure virtual]

Returns:
The standard deviation of the random variable.

Implemented in RealRandom, IntegerRandom, UniformRandomSimple, UniformRandom, NormalRandom, ExponentialRandom, DiscreteUniformRandom, and BernoulliRandom.

double rand (  )  [inline, protected]

Basic double precision random number.

Returns:
Random number in the range 0 to 1.

Definition at line 82 of file Random.H.

References randInt().

Referenced by NormalRandom::number(), BernoulliRandom::number(), UniformRandom::number(), and UniformRandomSimple::number().

MTRand::uint32 randInt (  )  [inline, protected]

Basic long integer random number.

Returns:
Random number in the range 0 to ULONG_MAX.

Definition at line 581 of file Random.H.

References left, pNext, and reload().

Referenced by DiscreteUniformRandom::number(), rand(), and randInt().

MTRand::uint32 randInt ( const uint32 n  )  [inline, protected]

Basic bounded long integer random number.

Parameters:
n Largest random number required.
Returns:
Random number in the range 0 to n.

Definition at line 595 of file Random.H.

References m, and randInt().

void reload (  )  [inline, private]

Definition at line 636 of file Random.H.

References left, M, N, pNext, state, and twist().

Referenced by randInt(), and setSeed().

uint32 hiBit ( const uint32 u  )  const [inline, private]

Definition at line 101 of file Random.H.

Referenced by mixBits().

uint32 loBit ( const uint32 u  )  const [inline, private]

Definition at line 102 of file Random.H.

Referenced by twist().

uint32 loBits ( const uint32 u  )  const [inline, private]

Definition at line 103 of file Random.H.

Referenced by mixBits().

uint32 mixBits ( const uint32 u,
const uint32 v 
) const [inline, private]

Definition at line 104 of file Random.H.

References hiBit(), and loBits().

Referenced by twist().

uint32 twist ( const uint32 m,
const uint32 s0,
const uint32 s1 
) const [inline, private]

Definition at line 106 of file Random.H.

References loBit(), MAGIC, and mixBits().

Referenced by reload().

MTRand& operator= ( const MTRand mtrand  )  [private]


Member Data Documentation

uint32 state[N] [private]

Definition at line 95 of file Random.H.

Referenced by reload(), and setSeed().

uint32* pNext [private]

Definition at line 96 of file Random.H.

Referenced by randInt(), and reload().

int left [private]

Definition at line 97 of file Random.H.

Referenced by randInt(), and reload().


The documentation for this class was generated from the following file:
Generated on Thu Feb 1 15:31:55 2007 for WURDE by  doxygen 1.5.1