#include <icy/random.h>Random implements a pseudo random number generator (PRNG) using the Mersenne Twister algorithm (std::mt19937).
| Return | Name | Description |
|---|---|---|
Random | Creates and initializes the PRNG. The stateSize parameter is accepted for API compatibility but is ignored; the engine always uses mt19937's fixed state size. | |
~Random | Destroys the PRNG. | |
void | seed | Seeds the pseudo random generator with the given seed. |
void | seed | Seeds the pseudo random generator with entropy from std::random_device. |
uint32_t | next | Returns the next pseudo random number from the mt19937 engine. |
uint32_t | next | Returns the next pseudo random number in the range [0, n). |
char | nextChar | Returns the next pseudo random byte as a char. |
bool | nextBool | Returns the next pseudo random boolean value. |
float | nextFloat | Returns the next pseudo random float in [0.0, 1.0]. |
double | nextDouble | Returns the next pseudo random double in [0.0, 1.0]. |
Random(int stateSize)Creates and initializes the PRNG. The stateSize parameter is accepted for API compatibility but is ignored; the engine always uses mt19937's fixed state size.
stateSize Ignored; present for API compatibility only.~Random()Destroys the PRNG.
void seed(uint32_t seed)Seeds the pseudo random generator with the given seed.
seed 32-bit seed value.void seed()Seeds the pseudo random generator with entropy from std::random_device.
uint32_t next()Returns the next pseudo random number from the mt19937 engine.
Pseudo random uint32_t value.
uint32_t next(uint32_t n)Returns the next pseudo random number in the range [0, n).
n Upper bound (exclusive).Pseudo random value in [0, n).
char nextChar()Returns the next pseudo random byte as a char.
Pseudo random char value.
bool nextBool()Returns the next pseudo random boolean value.
true or false with equal probability.
float nextFloat()Returns the next pseudo random float in [0.0, 1.0].
Pseudo random float value.
double nextDouble()Returns the next pseudo random double in [0.0, 1.0].
Pseudo random double value.
| Return | Name | Description |
|---|---|---|
void | getSeed static | Fills the buffer with cryptographically random bytes from std::random_device. |
static
static void getSeed(char * seed, unsigned length)Fills the buffer with cryptographically random bytes from std::random_device.
seed Buffer to fill.
length Number of bytes to write into seed.
| Return | Name | Description |
|---|---|---|
std::mt19937 | _engine |
std::mt19937 _engine