Egglib 2.1.11
C++ library reference manual
Public Member Functions | List of all members
Random Class Reference

Pseudo-random number generator. More...

#include <Random.hpp>

Public Member Functions

 Random ()
 Initializes using default seeds. More...
 
 Random (double seed1, double seed2)
 Initializes using given seeds. More...
 
double erand (double expectation)
 Draws a number from an exponential distribution. More...
 
unsigned int irand (unsigned int max)
 Draws an integer from a uniform distribution bound by 0 and max (max is not included) More...
 
unsigned int prand (double p)
 Draws an integer from a Poisson distribution with parameter p. More...
 
double nrand ()
 Draws a number from a normal distribution of expectation 0 and variance 1. More...
 
unsigned int grand (double)
 Draws a number from a geometric law. More...
 
double uniform ()
 Draws a number from a uniform distribution between 0 and 1. More...
 
double seed1 () const
 Gets the current value of the first seed. More...
 
double seed2 () const
 Gets the current value of the second seed. More...
 
void seed1 (double)
 Sets the current value of the first seed. More...
 
void seed2 (double)
 Sets the current value of the second seed. More...
 

Detailed Description

Pseudo-random number generator.

Random is a pseudo-random number generator, adapted from a part of MStrat, developed by Charles-Edouard Coste, Thomas M. Bataillon, Mathieu Cotisson, Guy Decoux, Chistophe Rozale, Daniel J. Schoen and Jacques L. David.

It uses two different seeds. By default, they are initialized to available arbitrary values. However, a given sequence can be repeated by passing the same two seeds.

Constructor & Destructor Documentation

Random ( )

Initializes using default seeds.

Uses the current system time and the memory address of the object as an attempt to generate unique sequences.

Random ( double  seed1,
double  seed2 
)

Initializes using given seeds.

This constructor can be used to reproduce a given sequence.

Member Function Documentation

double erand ( double  expectation)

Draws a number from an exponential distribution.

Parameters
expectationthe distribution mean (also 1/lambda where lambda is the rate parameter).
unsigned int grand ( double  param)

Draws a number from a geometric law.

Parameters
paramthe parameter of the law
unsigned int irand ( unsigned int  max)

Draws an integer from a uniform distribution bound by 0 and max (max is not included)

max is not included.

double nrand ( )

Draws a number from a normal distribution of expectation 0 and variance 1.

The algorithm used is the polar form of the Box-Muller algorithm.

unsigned int prand ( double  p)

Draws an integer from a Poisson distribution with parameter p.

The Poisson transformation algorithm was taken from (in French) http://www.u-picardie.fr/~cochard/IEM/demos/C107/C107_3.htm.

double seed1 ( ) const

Gets the current value of the first seed.

void seed1 ( double  seed)

Sets the current value of the first seed.

double seed2 ( ) const

Gets the current value of the second seed.

void seed2 ( double  seed)

Sets the current value of the second seed.

double uniform ( )

Draws a number from a uniform distribution between 0 and 1.


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

Hosted by 
Get EggLib at SourceForge.net. Fast, secure and Free Open Source software downloads