View source code
Display the source code in std/random.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla 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 local clone.

Struct std.random.MersenneTwisterEngine

The Mersenne Twister generator.

struct MersenneTwisterEngine(UIntType, ulong w, ulong n, ulong m, ulong r, UIntType a, ulong u, UIntType d, ulong s, UIntType b, ulong t, UIntType c, ulong l, UIntType f)
  
if (isUnsigned!UIntType);

Constructors

NameDescription
this (value) Constructs a MersenneTwisterEngine object.

Properties

NameTypeDescription
front[get] UIntTypeReturns the current random value.
save[get] typeof(this)

Methods

NameDescription
defaultState () Generates the default initial state for a Mersenne Twister; equivalent to the internal state obtained by calling seed(defaultSeed)
popFront () Advances the generator.
seed (value) Seeds a MersenneTwisterEngine object.
seed (range) Seeds a MersenneTwisterEngine object using an InputRange.
seedImpl (value, mtState) Implementation of the seeding mechanism, which can be used with an arbitrary State instance
seedImpl (range, mtState) Implementation of the range-based seeding mechanism, which can be used with an arbitrary State instance

Example

// seed with a constant
Mt19937 gen;
auto n = gen.front; // same for each run
writeln(n); // 3499211612

// Seed with an unpredictable value
gen.seed(unpredictableSeed);
n = gen.front; // different across runs

Authors

Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)

License

Boost License 1.0.