LinearCongruentialEngine

Linear Congruential generator. When m = 0, no modulus is used.

Constructors

this
this(UIntType x0)

Constructs a LinearCongruentialEngine generator seeded with x0.

Members

Functions

popFront
void popFront()

Advances the random sequence.

seed
void seed(UIntType x0)

(Re)seeds the generator.

Properties

front
UIntType front [@property getter]

Returns the current number in the random sequence.

save
typeof(this) save [@property getter]

Variables

empty
enum bool empty;

Always false (random generators are infinite ranges).

hasFixedRange
enum bool hasFixedRange;

Does this generator have a fixed range? (true).

increment
enum UIntType increment;

The parameters of this distribution. The random number is x = (x * multipler + increment) % modulus.

isUniformRandom
enum bool isUniformRandom;

Mark this as a Rng

max
enum UIntType max;

Highest generated value (modulus - 1).

min
enum UIntType min;

Lowest generated value (1 if c == 0, 0 otherwise).

modulus
enum UIntType modulus;

The parameters of this distribution. The random number is x = (x * multipler + increment) % modulus.

multiplier
enum UIntType multiplier;

The parameters of this distribution. The random number is x = (x * multipler + increment) % modulus.

Examples

Declare your own linear congruential engine

alias CPP11LCG = LinearCongruentialEngine!(uint, 48271, 0, 2_147_483_647);

// seed with a constant
auto rnd = CPP11LCG(42);
auto n = rnd.front; // same for each run
assert(n == 2027382);

Declare your own linear congruential engine

// glibc's LCG
alias GLibcLCG = LinearCongruentialEngine!(uint, 1103515245, 12345, 2_147_483_648);

// Seed with an unpredictable value
auto rnd = GLibcLCG(unpredictableSeed);
auto n = rnd.front; // different across runs

Declare your own linear congruential engine

// Visual C++'s LCG
alias MSVCLCG = LinearCongruentialEngine!(uint, 214013, 2531011, 0);

// seed with a constant
auto rnd = MSVCLCG(1);
auto n = rnd.front; // same for each run
assert(n == 2745024);

Meta