RNG Class Reference

This class defines a generator for uniformally distributed pseudo random numbers of the interval (0,1). More...

#include <RNG.h>

List of all members.

Public Member Functions

 RNG (long s=1)
 Creates a new pseudo random number instance and generates seed values for the three internal number generators.
void seed (long s=time(NULL))
 Uses "s" to generate the seed values for the three internal random number generators.
void reset ()
 Resets the current results of the three internal random number generators to the seed values.
long genLong ()
 Returns a new discrete uniformally distributed pseudo random number from the interval (0,1).
double genDouble ()
 Returns a new continuous uniformally distributed pseudo random number from the interval (0,1).
void getStatus (unsigned &x, unsigned &y, unsigned &z) const
 Returns the current results of the three internal random number generators.
void setStatus (const unsigned x, const unsigned y, const unsigned z)
 Sets the current results of the three internal random number generators.
virtual double operator() ()
 Returns a new continuous uniformally distributed pseudo random number of the interval (0,1).

Static Public Attributes

static RNG globalRng


Detailed Description

This class defines a generator for uniformally distributed pseudo random numbers of the interval (0,1).

A computer can only create "pseudo-random numbers", i.e. a sequence of numbers generated in some systematic way such that its statistical properties are as close as possible to those of true random numbers, e.g. negligible correlation between consecutive numbers. The most common methods are based on the "multiplicative congruential algorithm".
This basic algorithm is defined as:

$ n_i \equiv ( a \cdot n_{i-1} ) \pmod m $

The resulting integers $n_i$ are then divided by $m$ to give uniformly distributed pseudo-random numbers lying in the interval (0,1).
The start number $n_0$ is also called the "seed".
As you can see the random numbers created are cyclic with a maximum frequency of $m$. When choosing unintelligent numbers for $a$ and $m$, the frequency will be further shortened.
The aim is to achieve a most possible large frequency.
Therefore, this class uses an alternative algorithm, the Wichman-Hill algorithm, that uses three generators:

$ \mbox{\ }\\ \noindent n_{1,i} \equiv ( a_1 \cdot n_{1, i-1} ) \pmod {m_1}\\ n_{2,i} \equiv ( a_2 \cdot n_{2, i-1} ) \pmod {m_2}\\ n_{3,i} \equiv ( a_3 \cdot n_{3, i-1} ) \pmod {m_3} $

From this the pseudo random numbers $U_i$ are generated as:

$ U_i \equiv (\frac{n_{1,i}}{m_1} + \frac{n_{2,i}}{m_2} + \frac{n_{3,i}}{m_3}) \pmod {1.0} $

The random numbers $U_i$ are uniformally distributed in the interval (0,1).
By using intelligent numbers for $a_i$ and $m_i$ for $i = 1, 2, 3$ a frequency of $6953607871644$ is achieved.
For more information about this algorithm please refer to the BYTE magazine, March, 1987, pp. 127-128.
There will be one static instance of this class named globalRng. This instance can be used as base for the template class RandomVar from which all random generators used in library "#Rng" are derived.
This is done, because for every distribution simulation, where the distribution is not uniform, the uniformally distributed pseudo random numbers delivered by this class are transformed to the types of the other distributions.
So, if you have the uniformally distributed random numbers $z_i$ you can transform them into random numbers $x_i$ that are distributed by the function $F(X)$ by applying the inverse function of $F$ to $z_i$:

$ x_i = F^{-1}(z_i) $

This is also called the inverse transformation.

Author:
M. Kreutz
Date:
1998-08-17
Changes:
none
Status:
stable

Constructor & Destructor Documentation

RNG::RNG ( long  s = 1  )  [inline]

Creates a new pseudo random number instance and generates seed values for the three internal number generators.

s is used as base for the generation of the seed numbers $n_{0,1},\mbox{\ }n_{0,2},\mbox{\ }n_{0,3}$ (see description of the class) for the three number generators.

Parameters:
s the base for the generation of the three seed values, by default the value "1" is taken.
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable


Member Function Documentation

void RNG::seed ( long  s = time( NULL )  )  [inline]

Uses "s" to generate the seed values for the three internal random number generators.

s is used as base for the generation of the seed numbers $n_{0,1},\mbox{\ }n_{0,2},\mbox{\ }n_{0,3}$ (see description of the class) for the three number generators.

Parameters:
s the base for the generation of the three seed values, by default the current system clock time is taken (i.e. the number of seconds since 00:00 hours, Jan 1, 1970 UTC).
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

void RNG::reset (  )  [inline]

Resets the current results of the three internal random number generators to the seed values.

The current results $n_{i,1},\mbox{\ }n_{i,2},\mbox{\ }n_{i,3}$ (see description of the class) for the three number generators are set to the stored seed values $n_{0,1},\mbox{\ }n_{0,2},\mbox{\ }n_{0,3}$.

Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

long RNG::genLong (  )  [inline]

Returns a new discrete uniformally distributed pseudo random number from the interval (0,1).

Generates and returns the current random number $U_i$ (see description of class) in the interval (0,1). The type of the random number will be "long", so the original continuous type of the random number will be transformed to a discrete type.

Returns:
the current random number $U_i$ as long value
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

double RNG::genDouble (  )  [inline]

Returns a new continuous uniformally distributed pseudo random number from the interval (0,1).

Generates and returns the current random number $U_i$ (see description of class) in the interval (0,1). The type of the continuous random number will be "double".

Returns:
the current random number $U_i$ as double value
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

void RNG::getStatus ( unsigned &  x,
unsigned &  y,
unsigned &  z 
) const [inline]

Returns the current results of the three internal random number generators.

Stores the current values of $n_{i,1},\mbox{\ }n_{i,2},\mbox{\ }n_{i,3}$ (see description of the class) in x, y and z.

Parameters:
x the current result $n_{i,1}$ of generator no. 1
y the current result $n_{i,2}$ of generator no. 2
z the current result $n_{i,3}$ of generator no. 3
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

void RNG::setStatus ( const unsigned  x,
const unsigned  y,
const unsigned  z 
) [inline]

Sets the current results of the three internal random number generators.

Sets the current values of $n_{i,1},\mbox{\ }n_{i,2},\mbox{\ }n_{i,3}$ (see description of the class), that will be used as base for the generation of the next random number.

Parameters:
x the new current result $n_{i,1}$ of generator no. 1
y the new current result $n_{i,2}$ of generator no. 2
z the new current result $n_{i,3}$ of generator no. 3
Returns:
none
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable

virtual double RNG::operator() (  )  [inline, virtual]

Returns a new continuous uniformally distributed pseudo random number of the interval (0,1).

Generates and returns the current random number $U_i$ (see description of the class) as continuous value of type "double".

Returns:
the current random number $U_i$ as double value
Author:
M. Kreutz
Date:
1998-08-17
Changes
none
Status
stable


Member Data Documentation

RNG RNG::globalRng [static]

Global instantiation of class RNG, can be used by all random number generators in library "#Rng".

Global instantiation of class RNG, that can be used by all random number generators in library "#Rng".


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

Generated on Thu Aug 28 18:34:53 2008 for Dolphin by  doxygen 1.5.6