Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


Linear Congruential generator.
Andrei Alexandrescu Ilya Yaroshenko (rework)
struct LinearCongruentialEngine(Uint, Uint a, Uint c, Uint m) if (isUnsigned!Uint);
Linear Congruential generator.
enum auto isRandomEngine;
enum Uint max;
Highest generated value (modulus - 1 - bool(c == 0)).
enum Uint multiplier;

enum Uint increment;

enum Uint modulus;
The parameters of this distribution. The random number is x = (x * multipler + increment) % modulus.
pure @safe this(Uint x0);
Constructs a LinearCongruentialEngine generator seeded with x0.
Uint x0 seed, must be positive if c equals to 0.
pure nothrow @nogc @safe Uint opCall();
Advances the random sequence.
alias MinstdRand0 = LinearCongruentialEngine!(uint, 16807u, 0u, 2147483647u).LinearCongruentialEngine;

alias MinstdRand = LinearCongruentialEngine!(uint, 48271u, 0u, 2147483647u).LinearCongruentialEngine;
Define LinearCongruentialEngine generators with well-chosen parameters. MinstdRand0 implements Park and Miller's "minimal standard" generator that uses 16807 for the multiplier. MinstdRand implements a variant that has slightly better spectral behavior by using the multiplier 48271. Both generators are rather simplistic.
import mir.random.engine;
// seed with a constant
auto rnd0 = MinstdRand0(1);
auto n = rnd0(); // same for each run
// Seed with an unpredictable value
rnd0 = MinstdRand0(cast(uint)unpredictableSeed);
n = rnd0(); // different across runs

import std.traits;
static assert(is(ReturnType!rnd0 == uint));