A pseudo-random number generator engine that produces unsigned integer numbers in the closed interval [0,2w-1].

The algorithm used by this engine is optimized to compute large series of numbers (such as in Monte Carlo experiments) with an almost uniform distribution in the range.

The engine has an internal state sequence of n integer elements, which is filled with a pseudo-random series generated on construction or by calling member function seed.

The internal state sequence becomes the source for n elements: When the state is advanced (for example, in order to produce a new random number), the engine alters the state sequence by twisting the current value using xor mask a on a mix of bits determined by parameter r that come from that value and from a value m elements away (see operator() for details).

The random numbers produced are tempered versions of these twisted values. The tempering is a sequence of shift and xor operations defined by parameters u, d, s, b, t, c and l applied on the selected state value (see operator()).

The random numbers generated by mersenne_twister_engine have a period equivalent to the mersenne number 2(n-1)*w-1.

Template parameters

UIntType

An unsigned integer type.
Values produced by the engine are of this type.

w

Word size: Number of bits of each word in the state sequence.
This parameter should be lower or equal to numeric_limits<UIntType>::digits.

n

State size: Number of elements in the state sequence. This determines the degree of recurrence in the generated series.

m

Shift size: On each twist, the elements are transformed using other values in the sequence that are m elements away.
This parameter should be lower than or equal to n.

r

Mask bits: The number of bits that mark the separation point of words on each twist.
This parameter should be lower than or equal to w.

a

Xor Mask: The XOR mask to be applied as the linear function on each twist.
This parameter should be lower than (1u<<w).

s, t, u, l

Tempering shift parameters: Shift values for the scrambling operation used by the generation algorithm.
These parameters should be lower than or equal to w.

b, c, d

Tempering bitmask parameters: Bitmask values for the scrambling operation used by the generation algorithm.
These parameters should be lower than (1u<<w).

f

Initialization multiplier: The initialization multiplier used to seed the state sequence when a single value is used as seed.