Home
Base module

Random

Random implements a pseudo random number generator (PRNG) using the Mersenne Twister algo

Random

#include <icy/random.h>
class Random

Defined in src/base/include/icy/random.h:25

Random implements a pseudo random number generator (PRNG) using the Mersenne Twister algorithm (std::mt19937).

List of all members

NameKindOwner
RandomfunctionDeclared here
~RandomfunctionDeclared here
seedfunctionDeclared here
seedfunctionDeclared here
nextfunctionDeclared here
nextfunctionDeclared here
nextCharfunctionDeclared here
nextBoolfunctionDeclared here
nextFloatfunctionDeclared here
nextDoublefunctionDeclared here
getSeedfunctionDeclared here
_enginevariableDeclared here

Public Methods

ReturnNameDescription
RandomCreates and initializes the PRNG. The stateSize parameter is accepted for API compatibility but is ignored; the engine always uses mt19937's fixed state size.
~RandomDestroys the PRNG.
voidseedSeeds the pseudo random generator with the given seed.
voidseedSeeds the pseudo random generator with entropy from std::random_device.
uint32_tnextReturns the next pseudo random number from the mt19937 engine.
uint32_tnextReturns the next pseudo random number in the range [0, n).
charnextCharReturns the next pseudo random byte as a char.
boolnextBoolReturns the next pseudo random boolean value.
floatnextFloatReturns the next pseudo random float in [0.0, 1.0].
doublenextDoubleReturns the next pseudo random double in [0.0, 1.0].

Random

Random(int stateSize = 256)

Defined in src/base/include/icy/random.h:32

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.

Parameters

  • stateSize Ignored; present for API compatibility only.

~Random

~Random()

Defined in src/base/include/icy/random.h:35

Destroys the PRNG.


seed

void seed(uint32_t seed)

Defined in src/base/include/icy/random.h:39

Seeds the pseudo random generator with the given seed.

Parameters

  • seed 32-bit seed value.

seed

void seed()

Defined in src/base/include/icy/random.h:42

Seeds the pseudo random generator with entropy from std::random_device.


next

uint32_t next()

Defined in src/base/include/icy/random.h:46

Returns the next pseudo random number from the mt19937 engine.

Returns

Pseudo random uint32_t value.


next

uint32_t next(uint32_t n)

Defined in src/base/include/icy/random.h:51

Returns the next pseudo random number in the range [0, n).

Parameters

  • n Upper bound (exclusive).

Returns

Pseudo random value in [0, n).


nextChar

char nextChar()

Defined in src/base/include/icy/random.h:55

Returns the next pseudo random byte as a char.

Returns

Pseudo random char value.


nextBool

bool nextBool()

Defined in src/base/include/icy/random.h:59

Returns the next pseudo random boolean value.

Returns

true or false with equal probability.


nextFloat

float nextFloat()

Defined in src/base/include/icy/random.h:63

Returns the next pseudo random float in [0.0, 1.0].

Returns

Pseudo random float value.


nextDouble

double nextDouble()

Defined in src/base/include/icy/random.h:67

Returns the next pseudo random double in [0.0, 1.0].

Returns

Pseudo random double value.

Public Static Methods

ReturnNameDescription
voidgetSeed staticFills the buffer with cryptographically random bytes from std::random_device.

getSeed

static

static void getSeed(char * seed, unsigned length)

Defined in src/base/include/icy/random.h:72

Fills the buffer with cryptographically random bytes from std::random_device.

Parameters

  • seed Buffer to fill.

  • length Number of bytes to write into seed.

Private Attributes

ReturnNameDescription
std::mt19937_engine

_engine

std::mt19937 _engine

Defined in src/base/include/icy/random.h:75