Core 1.0
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Random Class Reference

This class implements several random number generators wrapped in a single class. More...

#include <random.h>

Public Member Functions

 Random (int=239)
 Creates a random number generator. More...
 
 ~Random ()
 Destroys a random number generator.
 
void Seed (int)
 Compute internal parameters given seed. More...
 
int Integer (int)
 Compute a uniform random integer from 0 to n-1. More...
 
double Uniform ()
 Compute uniform distribution in [0, 1.0[.
 
double Uniform (const double &)
 Compute uniform distribution in [0, a[. More...
 
double Uniform (const double &, const double &)
 Compute uniform distribution in [a, b[. More...
 
double Exponential (const double &)
 Normal distribution. More...
 
double NormalBoxMuller (const double &, const double &)
 Normal distribution using a Box-Muller algorithm. More...
 
double Angle (unsigned int)
 Generate a random angle.
 

Static Public Attributes

static Random R239
 This static member implements a simple random number generator with seed 239. More...
 

Protected Member Functions

int Int31 ()
 Generate a random integer. More...
 
int SimpleInt31 ()
 Computes 31 bit integer.
 

Detailed Description

This class implements several random number generators wrapped in a single class.

Constructor & Destructor Documentation

◆ Random()

Random::Random ( int  seed = 239)

Creates a random number generator.

Parameters
seedSeed argument used for initialization.

Member Function Documentation

◆ Exponential()

double Random::Exponential ( const double &  mu)

Normal distribution.

Parameters
sigmaStandard deviation.
meanMean value.

Exponential random sequence.

Give a random variate drawn with a uniform distribution T=-ln(1-U)/lamba has an exponential distribution. Since U is uniform, 1-U and U are equivalent, thus T=-ln(U)/lambda.

Parameters
muMu parameter, invese of lamba.

◆ Int31()

int Random::Int31 ( )
protected

Generate a random integer.

This is an implementation of Marsaglia's subtract-with-borrow generator. After The Annals of Applied Probability, 1(3), 462-480, 1991.

◆ Integer()

int Random::Integer ( int  n)

Compute a uniform random integer from 0 to n-1.

Parameters
nInteger.

◆ NormalBoxMuller()

double Random::NormalBoxMuller ( const double &  variance,
const double &  mean 
)

Normal distribution using a Box-Muller algorithm.

The Box–Muller transform is a pseudo-random number sampling method for generating pairs of independent, standard, normally distributed (zero expectation, unit variance) random numbers, given a source of uniformly distributed random numbers.

Parameters
varianceVariance.
meanMean.

◆ Seed()

void Random::Seed ( int  seed)

Compute internal parameters given seed.

Parameters
seedThe seed.

◆ Uniform() [1/2]

double Random::Uniform ( const double &  a)

Compute uniform distribution in [0, a[.

Parameters
aAmplitude.

◆ Uniform() [2/2]

double Random::Uniform ( const double &  a,
const double &  b 
)

Compute uniform distribution in [a, b[.

Parameters
a,bAmplitude interval.

Member Data Documentation

◆ R239

Random Random::R239
static

This static member implements a simple random number generator with seed 239.

This static member is a convenient way to generate random numbers on the fly wherever needed.