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

TRNG::RNG< RNG_type > Class Template Reference

pseudo random number generator template. More...

#include <trng.h>

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<class t_function> double rejection (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.

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


Detailed Description

template<class RNG_type>
class TRNG::RNG< RNG_type >

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:
Heiko Bauke

Definition at line 127 of file trng.h.


Member Function Documentation

template<class RNG_type>
const char* TRNG::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

Definition at line 151 of file trng.h.

template<class RNG_type>
void TRNG::RNG< RNG_type >::reset void    [inline]
 

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

Definition at line 160 of file trng.h.

template<class RNG_type>
void TRNG::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

Definition at line 173 of file trng.h.

template<class RNG_type>
long TRNG::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

Definition at line 185 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::boolean(), TRNG::RNG< LCG32 >::uniformcc(), TRNG::RNG< LCG32 >::uniformco(), TRNG::RNG< LCG32 >::uniformoc(), and TRNG::RNG< LCG32 >::uniformoo().

template<class RNG_type>
long TRNG::RNG< RNG_type >::max void    [inline]
 

Returns:
maximal pseudo random number returned by rand()

Definition at line 193 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::boolean(), TRNG::RNG< LCG32 >::uniformcc(), TRNG::RNG< LCG32 >::uniformco(), TRNG::RNG< LCG32 >::uniformoc(), and TRNG::RNG< LCG32 >::uniformoo().

template<class RNG_type>
bool TRNG::RNG< RNG_type >::boolean void    [inline]
 

Returns:
pseudo random boolean with probability for return value true

Definition at line 202 of file trng.h.

template<class RNG_type>
bool TRNG::RNG< RNG_type >::boolean const double    p [inline]
 

Returns:
pseudo random boolean with probability for return value true

Definition at line 211 of file trng.h.

template<class RNG_type>
double TRNG::RNG< RNG_type >::uniform void    [inline]
 

Returns:
a in uniform distributed random number

Definition at line 219 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::uniforml().

template<class RNG_type>
double TRNG::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 229 of file trng.h.

template<class RNG_type>
double TRNG::RNG< RNG_type >::uniformco void    [inline]
 

Returns:
a in uniform distributed random number

Definition at line 237 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::binomial_dist(), TRNG::RNG< LCG32 >::binomial_dist_tab(), TRNG::RNG< LCG32 >::discrete_dist(), TRNG::RNG< LCG32 >::Gamma_dist(), TRNG::RNG< LCG32 >::poisson_dist(), TRNG::RNG< LCG32 >::rejection(), TRNG::RNG< LCG32 >::spherical2d(), TRNG::RNG< LCG32 >::spherical3d(), TRNG::RNG< LCG32 >::spherical4d(), and TRNG::RNG< LCG32 >::uniform().

template<class RNG_type>
double TRNG::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 248 of file trng.h.

template<class RNG_type>
double TRNG::RNG< RNG_type >::uniformcc void    [inline]
 

Returns:
a in uniform distributed random number

Definition at line 257 of file trng.h.

template<class RNG_type>
double TRNG::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 268 of file trng.h.

template<class RNG_type>
double TRNG::RNG< RNG_type >::uniformoc void    [inline]
 

Returns:
a in uniform distributed random number

Definition at line 277 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::exp_dist().

template<class RNG_type>
double TRNG::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 288 of file trng.h.

template<class RNG_type>
double TRNG::RNG< RNG_type >::uniformoo void    [inline]
 

Returns:
a in uniform distributed random number

Definition at line 297 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::Gamma_dist(), TRNG::RNG< LCG32 >::geometric_dist(), TRNG::RNG< LCG32 >::laplace_dist(), TRNG::RNG< LCG32 >::normal_dist(), and TRNG::RNG< LCG32 >::tent_dist().

template<class RNG_type>
double TRNG::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 308 of file trng.h.

template<class RNG_type>
long TRNG::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 318 of file trng.h.

template<class RNG_type>
long TRNG::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 328 of file trng.h.

template<class RNG_type>
double TRNG::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 348 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::Student_t_dist().

template<class RNG_type>
double TRNG::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 389 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::Student_t_dist().

template<class RNG_type>
double TRNG::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 411 of file trng.h.

template<class RNG_type>
double TRNG::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 442 of file trng.h.

template<class RNG_type>
double TRNG::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 472 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::Beta_dist(), TRNG::RNG< LCG32 >::chi_square_dist(), TRNG::RNG< LCG32 >::Gamma_dist(), and TRNG::RNG< LCG32 >::poisson_dist().

template<class RNG_type>
double TRNG::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 550 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::binomial_dist().

template<class RNG_type>
double TRNG::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 575 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::Student_t_dist().

template<class RNG_type>
long TRNG::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 597 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::poisson_dist().

template<class RNG_type>
long TRNG::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 637 of file trng.h.

template<class RNG_type>
double TRNG::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 683 of file trng.h.

template<class RNG_type>
long TRNG::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 715 of file trng.h.

template<class RNG_type>
long TRNG::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 753 of file trng.h.

template<class RNG_type>
template<class t_function>
double TRNG::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 790 of file trng.h.

template<class RNG_type>
long TRNG::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 812 of file trng.h.

template<class RNG_type>
vector2d TRNG::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 839 of file trng.h.

template<class RNG_type>
vector3d TRNG::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 863 of file trng.h.

template<class RNG_type>
vector4d TRNG::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 887 of file trng.h.

template<class RNG_type>
void TRNG::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

Definition at line 918 of file trng.h.

template<class RNG_type>
void TRNG::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 929 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::jump().

template<class RNG_type>
void TRNG::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 948 of file trng.h.

template<class RNG_type>
void TRNG::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

Definition at line 964 of file trng.h.

Referenced by TRNG::RNG< LCG32 >::jump(), and TRNG::RNG< LCG32 >::jump2().

template<class RNG_type>
void TRNG::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 976 of file trng.h.

template<class RNG_type>
void TRNG::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

Definition at line 993 of file trng.h.

template<class RNG_type>
void TRNG::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

Definition at line 1003 of file trng.h.


Member Data Documentation

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

This numerical value determins the random number generator type.

Definition at line 143 of file trng.h.


The documentation for this class was generated from the following file:
Generated on Tue Dec 10 13:31:37 2002 for Tina's Random Number Generators by doxygen1.2.15