Core 1.0
|
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. | |
This class implements several random number generators wrapped in a single class.
Random::Random | ( | int | seed = 239 | ) |
Creates a random number generator.
seed | Seed argument used for initialization. |
double Random::Exponential | ( | const double & | mu | ) |
Normal distribution.
sigma | Standard deviation. |
mean | Mean 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.
mu | Mu parameter, invese of lamba. |
|
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.
int Random::Integer | ( | int | n | ) |
Compute a uniform random integer from 0 to n-1.
n | Integer. |
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.
variance | Variance. |
mean | Mean. |
void Random::Seed | ( | int | seed | ) |
Compute internal parameters given seed.
seed | The seed. |
double Random::Uniform | ( | const double & | a | ) |
Compute uniform distribution in [0, a[.
a | Amplitude. |
double Random::Uniform | ( | const double & | a, |
const double & | b | ||
) |
Compute uniform distribution in [a, b[.
a,b | Amplitude interval. |
|
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.