The OpenD Programming Language

Mt19937

A MersenneTwisterEngine instantiated with the parameters of the original engine MT19937, generating uniformly-distributed 32-bit numbers with a period of 2 to the power of 19937.

This is recommended for random number generation on 32-bit systems unless memory is severely restricted, in which case a Xorshift would be the generator of choice.

import mir.random.engine.mersenne_twister;
alias Mt19937 = MersenneTwisterEngine!(uint, 32, 624, 397, 31, 0x9908b0df, 11, 0xffffffff, 7, 0x9d2c5680, 15, 0xefc60000, 18, 1812433253)

Examples

import mir.random.engine;

// bit-masking by generator maximum is necessary
// to handle 64-bit `unpredictableSeed`
auto gen = Mt19937(unpredictableSeed & Mt19937.max);
auto n = gen();

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

Meta