Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

TRNG::RNG Class Template Reference

pseudo random number generator template. More...

#include <trng.h>

Inheritance diagram for TRNG::RNG:

TRNG::CLCG2 TRNG::CLCG3 TRNG::CLCG4 TRNG::EINV TRNG::EINVLCG64 TRNG::LCG32 TRNG::LCG64 TRNG::MRG2 TRNG::MRG3 TRNG::MRG4 TRNG::ParkMiller List of all members.

Public Methods

const char* name (void)
 pseudo random number generator's name. More...

void reset (void)
 reset the pseudo random number generator. More...

void seed (long s=0l)
 seed the pseudo random number generator. More...

long rand (void)
 next pseudo random number. More...

long max (void)
 maximal pseudo random number. More...

bool boolean (void)
 pseudo random boolean. More...

bool boolean (const double p)
 pseudo random boolean. More...

double uniform (void)
 pseudo random number. More...

double uniform (const double a, const double b)
 pseudo random number. More...

double uniformco (void)
 pseudo random number. More...

double uniformco (const double a, const double b)
 pseudo random number. More...

double uniformcc (void)
 pseudo random number. More...

double uniformcc (const double a, const double b)
 pseudo random number. More...

double uniformoc (void)
 pseudo random number. More...

double uniformoc (const double a, const double b)
 pseudo random number. More...

double uniformoo (void)
 pseudo random number. More...

double uniformoo (const double a, const double b)
 pseudo random number. More...

long uniforml (const long b)
 pseudo random number. More...

long uniforml (const long a, const long b)
 pseudo random number. More...

double normal_dist (const double sigma=1.0, const double mu=0.0)
 pseudo random number. More...

double exp_dist (const double mu=1.0)
 pseudo random number. More...

double laplace_dist (const double a=1.0)
 pseudorandom number. More...

double tent_dist (const double a=1.0)
 pseudorandom number. More...

double Gamma_dist (const double a, const double b)
 pseudo random number. More...

double Beta_dist (const double a, const double b)
 pseudo random number. More...

double chi_square_dist (const double nu)
 pseudo random number. More...

long binomial_dist (long n, double p=0.5)
 pseudo random number. More...

long binomial_dist_tab (long n, double p=0.5)
 pseudo random number. More...

double Student_t_dist (const double nu)
 pseudo random number. More...

long poisson_dist (double mu=1.0)
 pseudo random number. More...

long geometric_dist (double q)
 pseudo random number. More...

template<classt_function> double rejection<t_function> (t_function p, double a1, double a2, double p_max)
 pseudo random number. More...

long discrete_dist (const std::vector<double> p)
 pseudo random number. More...

vector2d spherical2d (void)
 pseudo random vector. More...

vector3d spherical3d (void)
 pseudo random vector. More...

vector4d spherical4d (void)
 pseudo random vector. More...

void split (long s, long n)
 sequence splitting. More...

void jump (long long s)
 sequence splitting. More...

void jump (long long s, long n)
 sequence splitting. More...

void jump2 (long s)
 sequence splitting. More...

void jump2 (long s, long n)
 sequence splitting. More...

void save_status (std::vector<long> &s)
 status saving. More...

void load_status (const std::vector<long> &s)
 status restoring. More...


Static Public Attributes

const TRNG::RNG_type type = RNG_t
 pseudo random number generator type. More...


Protected Attributes

long max_val
 maximum value that the random number gernerator's method rand() can return. More...

long max_val2
 the half of the maximum value that the random number gernerator's method rand() can return. More...


Detailed Description

template<class RNG_type> template class TRNG::RNG

pseudo random number generator template.

All the pseudo random number generators are derived form this base class. Routines for generation of uniform and nonuniform variartes are implemented in this base class. Generator specific tasks like sequence splitting or leapfrog method are implementetd by the derived classes. The method rand(), the generator's core method, has of course also to be reimplemented for every new generator.

Author(s):
Heiko Bauke

Definition at line 126 of file trng.h.


Member Function Documentation

template<classRNG_type>
const char * TRNG<RNG_type>::RNG<RNG_type>::name ( void ) [inline]
 

Returns a pointer to a zero terminated string containing the pseudo random number generator's name.

Returns:
pointer to a zero termiated string

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 150 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::reset ( void ) [inline]
 

The pseudo random number generator's parameters are set to some default values.

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 159 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::seed ( long s = 0l ) [inline]
 

The pseudo random number generator's state is set. Calling reset() and seed() with the seed value used by the initialisation will set the generator in the same state as after initialisation.

Parameters:
s   new seed
Exceptions:
error   if
See also:
TRNG::error

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 172 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::rand ( void ) [inline]
 

This is the generator's core method. It calculates the next pseudo random number. It's an integer number with . You can determine the upper bound by calling the method max().

Returns:
next integer pseudo random number

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 184 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::max ( void ) [inline]
 

Returns:
maximal pseudo random number returned by rand()

Definition at line 192 of file trng.h.

template<classRNG_type>
bool TRNG<RNG_type>::RNG<RNG_type>::boolean ( void ) [inline]
 

Returns:
pseudo random boolean with probability for return value true

Definition at line 201 of file trng.h.

template<classRNG_type>
bool TRNG<RNG_type>::RNG<RNG_type>::boolean ( const double p ) [inline]
 

Returns:
pseudo random boolean with probability for return value true

Definition at line 210 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniform ( void ) [inline]
 

Returns:
a in uniform distributed random number

Definition at line 218 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniform ( const double a,
const double b ) [inline]
 

Returns:
a in uniform distributed random number
Parameters:
a   lower bound
b   upper bound

Definition at line 228 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformco ( void ) [inline]
 

Returns:
a in uniform distributed random number

Definition at line 236 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformco ( const double a,
const double b ) [inline]
 

Returns:
a in uniform distributed random number
Parameters:
a   lower bound
b   upper bound

Definition at line 247 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformcc ( void ) [inline]
 

Returns:
a in uniform distributed random number

Definition at line 256 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformcc ( const double a,
const double b ) [inline]
 

Returns:
a in uniform distributed random number
Parameters:
a   lower bound
b   upper bound

Definition at line 267 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformoc ( void ) [inline]
 

Returns:
a in uniform distributed random number

Definition at line 276 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformoc ( const double a,
const double b ) [inline]
 

Returns:
a in uniform distributed random number
Parameters:
a   lower bound
b   upper bound

Definition at line 287 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformoo ( void ) [inline]
 

Returns:
a in uniform distributed random number

Definition at line 296 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::uniformoo ( const double a,
const double b ) [inline]
 

Returns:
a in uniform distributed random number
Parameters:
a   lower bound
b   upper bound

Definition at line 307 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::uniforml ( const long b ) [inline]
 

Returns:
If a in uniform distributed natural random number is returned, if return value is in .
Parameters:
b   upper bound

Definition at line 317 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::uniforml ( const long a,
const long b ) [inline]
 

Returns:
a in uniform distributed natural random number
Parameters:
a   lower bound
b   upper bound

Definition at line 327 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::normal_dist ( const double sigma = 1.0,
const double mu = 0.0 ) [inline]
 

A normal distributed random variate has a probability density

This method uses the polar (Box-Mueller) method.

Returns:
a normal distributed random number with mean and variance
Parameters:
sigma   variance
mu   mean
Exceptions:
error   if
See also:
TRNG::error

Definition at line 347 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::exp_dist ( const double mu = 1.0 ) [inline]
 

A exponential distributed random variate has a probability density

One random number is used to get one random number with exponential distribution.

Returns:
a exponential distributed random number with mean
Parameters:
mu   mean
Exceptions:
error   if
See also:
TRNG::error

Definition at line 388 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::laplace_dist ( const double a = 1.0 ) [inline]
 

The two-sided exponential probability distribution is

It is also known as the Laplace distribution. The is implementation adopted from the GNU scientific library and uses a simple transformation method. One random number is used to get one random number with Laplace distribution.

Returns:
a pseudo random number with probability density
Parameters:
a   parameter ,
Exceptions:
error   if
See also:
TRNG::error

Definition at line 410 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::tent_dist ( const double a = 1.0 ) [inline]
 

This method generates a pseudo randeom number with a tent shaped probability distribution.

The implementation uses a simple transformation method. One random number is used to get one random number with a tent shaped distribution.

Returns:
a pseudo random number with probability density
Parameters:
a   parameter ,
Exceptions:
error   if
See also:
TRNG::error

Definition at line 441 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::Gamma_dist ( const double a,
const double b ) [inline]
 

A gamma distributed random number has a probability density

The is implemetation adopted from the GNU scientific library.

Returns:
a gamma distributed random number
Parameters:
a   parameter
b   parameter
Exceptions:
error   if or
See also:
TRNG::error

Definition at line 471 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::Beta_dist ( const double a,
const double b ) [inline]
 

A Beta distributed random number has a probability density

Returns:
a Beta distributed random number
Parameters:
a   parameter ,
b   parameter ,
Exceptions:
error   if or
See also:
TRNG::error

Definition at line 549 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::chi_square_dist ( const double nu ) [inline]
 

The -distribution is just a special case of the -distribution with and .

Returns:
a chi square distributed random number
Parameters:
nu   degrees of freedom
Exceptions:
error   if
See also:
TRNG::error

Definition at line 574 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::binomial_dist ( long n,
double p = 0.5 ) [inline]
 

The binomial distribution is a discrete distribution with

The implemetation is adopted from the GNU scientific library.

Returns:
a binomial distributed pseudo random number
Parameters:
n   number of trails
p   probability in each trail
Exceptions:
error   if or or
See also:
TRNG::error

Definition at line 596 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::binomial_dist_tab ( long n,
double p = 0.5 ) [inline]
 

The binomial distribution is a discrete distribution with

This method's implementation uses a lookup table and is very fast if this method is called often with the same parameter set.

Returns:
a binomial distributed pseudo random number
Parameters:
n   number of trails
p   probability in each trail
Exceptions:
error   if or or
See also:
TRNG::error

Definition at line 636 of file trng.h.

template<classRNG_type>
double TRNG<RNG_type>::RNG<RNG_type>::Student_t_dist ( const double nu ) [inline]
 

Student's -distribution with degrees of freedom is defined as

This method's implementation is adopted from the GNU scientific library.

Returns:
a random number with Student's- distribution with degrees of freedom
Parameters:
nu   degrees of freedom,
Exceptions:
error   if
See also:
TRNG::error

Definition at line 682 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::poisson_dist ( double mu = 1.0 ) [inline]
 

The probability distribution for Poisson variates is

This method's implementation is adopted from the GNU scientific library.

Returns:
a poisson distributed pseudo random number
Parameters:
mu   mean
Exceptions:
error   if
See also:
TRNG::error

Definition at line 714 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::geometric_dist ( double q ) [inline]
 

The geometric probability distribution is

This method's implementation is adopted from the GNU scientific library.

Returns:
a geometric distributed pseudo random number
Parameters:
q   probability
Exceptions:
error   if or
See also:
TRNG::error

Definition at line 752 of file trng.h.

template<classRNG_type>
template<classt_function>
double TRNG<RNG_type>::RNG<RNG_type>::rejection ( t_function p,
double a1,
double a2,
double p_max ) [inline]
 

Returns a random number calculated by the rejection method. Assume your desired probability distribution is for . Write a class that calculates this probability distribution

class p {
public:
  double operator()(double x) {
    return 0.75*(1.0-x*x);
  }
};
and use
my_rng.rejection(p(), -1.0, 1.0, 0.75)
to generate a pseudo random number with probability distribution .
Returns:
random number
Parameters:
p   function object, a function describing the probability density in the range between and
a1   lower bound
a2   upper bound
p_max   maximum of the probability function for

Definition at line 789 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::discrete_dist ( const std::vector< double > p ) [inline]
 

This method can be used to generate discrete random variates with an arbitrary probability distribution. The algorithm is .

Returns:
random number ,
Parameters:
p   dimensional commulative probability vector , , with and
Exceptions:
error   if vector empty
See also:
TRNG::error

Definition at line 811 of file trng.h.

template<classRNG_type>
vector2d TRNG<RNG_type>::RNG<RNG_type>::spherical2d ( void ) [inline]
 

This method calculates a unit vector with a uniform distributed direction in two dimensions. For a vector uniform distributed inside the unit citcle multiply the vector with where is uniforum distributed in . The vector is stored in a structure vector2d.

Returns:
a two dimensional unit vector

Definition at line 838 of file trng.h.

template<classRNG_type>
vector3d TRNG<RNG_type>::RNG<RNG_type>::spherical3d ( void ) [inline]
 

This method calculates a unit vector with a uniform distributed direction in three dimensions. For a vector uniform distributed inside the unit shere multiply the vector with where is uniforum distributed in . The vector is stored in a structure vector3d.

Returns:
a three dimensional unit vector

Definition at line 862 of file trng.h.

template<classRNG_type>
vector4d TRNG<RNG_type>::RNG<RNG_type>::spherical4d ( void ) [inline]
 

This method calculates a unit vector with a uniform distributed direction in four dimensions. For a vector uniform distributed inside the unit hyper-shere multiply the vector with where is uniforum distributed in . The vector is stored in a structure vector4d.

Returns:
a four dimensional unit vector

Definition at line 886 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::split ( long s,
long n ) [inline]
 

The pseudo random number generator's sequence is splitted into sequences using the leapfrog method. Sequence number is selected.

Parameters:
s   number of sequences
n   selected sequence
Exceptions:
error   if or or
See also:
TRNG::error

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 917 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::jump ( long long s ) [inline]
 

The pseudo random number generator jumps steps ahead.

Parameters:
s   determines the jump size
Exceptions:
error   if
See also:
TRNG::error

Definition at line 928 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::jump ( long long s,
long n ) [inline]
 

The pseudo random number generator jumps steps ahead.

Parameters:
s   determines the jump size
Exceptions:
error   if or
See also:
TRNG::error

Definition at line 947 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::jump2 ( long s ) [inline]
 

The pseudo random number generator jumps steps ahead.

Parameters:
s   determines the jump size
Exceptions:
error   if
See also:
TRNG::error

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 963 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::jump2 ( long s,
long n ) [inline]
 

The pseudo random number generator jumps steps ahead.

Parameters:
s   determines the jump size
n   determines the jump size
Exceptions:
if   or
See also:
TRNG::error

Definition at line 975 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::save_status ( std::vector< long >& s ) [inline]
 

The status of the pseudo random number generator is saved into a vector.

Parameters:
s   reference to a vector of long

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 992 of file trng.h.

template<classRNG_type>
void TRNG<RNG_type>::RNG<RNG_type>::load_status ( const std::vector< long >& s ) [inline]
 

The status of the pseudo random number generator is restored from a vector.

Parameters:
s   reference to a vector of long

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 1002 of file trng.h.


Member Data Documentation

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::max_val [protected]
 

Definition at line 134 of file trng.h.

template<classRNG_type>
long TRNG<RNG_type>::RNG<RNG_type>::max_val2 [protected]
 

Definition at line 136 of file trng.h.

template<classRNG_type>
const TRNG<RNG_type>::RNG_type TRNG<RNG_type>::RNG<RNG_type>::type = RNG_t [static]
 

This numerical value determins the random number generator type.

Reimplemented in TRNG::ParkMiller, TRNG::LCG32, TRNG::LCG64, TRNG::MRG2, TRNG::MRG3, TRNG::MRG4, TRNG::CLCG2, TRNG::CLCG3, TRNG::CLCG4, TRNG::EINV, and TRNG::EINVLCG64.

Definition at line 142 of file trng.h.


The documentation for this class was generated from the following file:
Generated at Tue Apr 30 12:03:22 2002 for Tina's Random Number Generators by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000