This class implements several random number generators wrapped in a single class.
More...
#include <random.h>
|
| Random (int=239) |
| Creates a random number generator.
|
|
| ~Random () |
| Destroys a random number generator.
|
|
void | Seed (int) |
| Compute internal parameters given seed.
|
|
int | Integer (int) |
| Compute a uniform random integer from 0 to n-1.
|
|
double | Uniform () |
| Compute uniform distribution in [0, 1.0[.
|
|
double | Uniform (const double &) |
| Compute uniform distribution in [0, a[.
|
|
double | Uniform (const double &, const double &) |
| Compute uniform distribution in [a, b[.
|
|
double | Exponential (const double &) |
| Exponential random sequence.
|
|
double | NormalBoxMuller (const double &, const double &) |
| Normal distribution using a Box-Muller algorithm.
|
|
double | Angle (unsigned int) |
| Generate a random angle.
|
|
|
static Random | R239 |
| This static member implements a simple random number generator with seed 239.
|
|
|
int | Int31 () |
| Generate a random integer.
|
|
int | SimpleInt31 () |
| Computes 31 bit integer.
|
|
This class implements several random number generators wrapped in a single class.
◆ Random()
Random::Random |
( |
int | seed = 239 | ) |
|
Creates a random number generator.
- Parameters
-
seed | Seed argument used for initialization. |
◆ Exponential()
double Random::Exponential |
( |
const double & | mu | ) |
|
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
-
mu | Mu parameter, invese of lamba. |
◆ Int31()
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
-
◆ 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
-
variance | Variance. |
mean | Mean. |
◆ Seed()
void Random::Seed |
( |
int | seed | ) |
|
Compute internal parameters given seed.
- Parameters
-
◆ Uniform() [1/2]
double Random::Uniform |
( |
const double & | a | ) |
|
Compute uniform distribution in [0, a[.
- Parameters
-
◆ Uniform() [2/2]
double Random::Uniform |
( |
const double & | a, |
|
|
const double & | b ) |
Compute uniform distribution in [a, b[.
- Parameters
-
◆ R239
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.