Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
A random engine. More...
#include <gf/Random.h>
Public Member Functions | |
Random () | |
Default constructor with complex initialization. More... | |
Random (std::uint_fast32_t seed) | |
Constructor with simple initialization. More... | |
template<typename T > | |
T | computeUniformInteger (T min, T max) |
Compute an integer with a uniform distribution. More... | |
template<typename T > | |
T | computeUniformFloat (T min, T max) |
Compute a float with a uniform distribution. More... | |
template<typename T > | |
T | computeNormalFloat (T mean, T stddev) |
Compute a float with a normal (Gaussian) distribution. More... | |
bool | computeBernoulli (double p) |
Compute a boolean with a Bernoulli distribution. More... | |
std::mt19937 & | getEngine () |
Get the underlying engine. More... | |
A random engine.
gf::Random is a wrapper around C++11 standard random features. It embeds a Mersenne Twister engine and provides several distributions above this engine.
gf::Random::Random | ( | ) |
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.
|
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^{32} \) possible states. Choose this constructor if you need reproducible randomness as a same seed will always provide the same sequence.
seed | The seed for the engine |
|
inline |
Compute a boolean with a Bernoulli distribution.
p | The probability of true |
Compute a float with a normal (Gaussian) distribution.
mean | The mean of the distribution |
stddev | The standard deviation of the distribution |
Compute a float with a uniform distribution.
min | The minimum value (inclusive) |
max | The maximum value (exclusive) |
min
and max
Compute an integer with a uniform distribution.
min | The minimum value (inclusive) |
max | The maximum value (inclusive) |
min
and max
|
inline |
Get the underlying engine.