A set of random utilities.
More...
#include <gf/Random.h>
A set of random utilities.
gf::Random is a wrapper around C++11 standard random features. It embeds a random engine and provides several distributions above this engine.
- See also
- gf::RandomEngine
◆ Random() [1/2]
Default constructor with complex initialization.
This constructor initializes the Mersenne Twister thanks to a random device and a seed sequence. This ensures that the state of the engine is different for each instanciation. Choose this constructor if you need good statistical randomness.
◆ Random() [2/2]
gf::Random::Random |
( |
uint64_t |
seed | ) |
|
|
inline |
Constructor with simple initialization.
This constructor initializes the Mersenne Twister with a single seed. This method is easy but not very good because it allows only \( 2^{64} \) possible states. Choose this constructor if you need reproducible randomness as a same seed will always provide the same sequence.
- Parameters
-
seed | The seed for the engine |
◆ computeAngle()
float gf::Random::computeAngle |
( |
| ) |
|
Compute a uniform angle in the range \( [ 0, 2 \pi ] \).
- Returns
- A valid angle
◆ computeBernoulli()
bool gf::Random::computeBernoulli |
( |
double |
p | ) |
|
|
inline |
Compute a boolean with a Bernoulli distribution.
- Parameters
-
- Returns
- true with a probability of \( p \).
◆ computeId()
gf::Id gf::Random::computeId |
( |
| ) |
|
◆ computeNormalFloat()
template<typename T >
T gf::Random::computeNormalFloat |
( |
T |
mean, |
|
|
T |
stddev |
|
) |
| |
|
inline |
Compute a float with a normal (Gaussian) distribution.
- Parameters
-
mean | The mean of the distribution |
stddev | The standard deviation of the distribution |
- Returns
- A value with a normal distribution
◆ computePosition() [1/3]
Compute a uniform position in a circle.
- Parameters
-
- Returns
- A value in the circle
◆ computePosition() [2/3]
Compute a uniform position in a given area.
- Parameters
-
- Returns
- A value in the area
◆ computePosition() [3/3]
Compute a uniform position in a given area.
- Parameters
-
- Returns
- A value in the area
◆ computeRadius()
float gf::Random::computeRadius |
( |
float |
radiusMin, |
|
|
float |
radiusMax |
|
) |
| |
Compute a uniform radius.
- Parameters
-
radiusMin | The minimum radius |
radiusMax | The maximum radius |
- Returns
- A valid radius
◆ computeUniformFloat()
template<typename T >
T gf::Random::computeUniformFloat |
( |
T |
min, |
|
|
T |
max |
|
) |
| |
|
inline |
Compute a float with a uniform distribution.
- Parameters
-
min | The minimum value (inclusive) |
max | The maximum value (exclusive) |
- Returns
- A value between
min
and max
◆ computeUniformInteger()
template<typename T >
T gf::Random::computeUniformInteger |
( |
T |
min, |
|
|
T |
max |
|
) |
| |
|
inline |
Compute an integer with a uniform distribution.
- Parameters
-
min | The minimum value (inclusive) |
max | The maximum value (inclusive) |
- Returns
- A value between
min
and max
◆ getEngine()
Get the underlying engine.
- Returns
- A reference to the engine