class template
<random>

std::mersenne_twister_engine

template <class UIntType, size_t w, size_t n, size_t m, size_t r,          UIntType a, size_t u, UIntType d, size_t s,          UIntType b, size_t t,          UIntType c, size_t l, UIntType f>  class mersenne_twister_engine;
Mersenne twister random number engine
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.

Template instantiations


Member types

The following alias is a member type of mersenne_twister_engine:

member typedefinitionnotes
result_typeThe first template parameter (UIntType)The type of the numbers generated.

Member functions


Non-member functions


Member constexpr constants

member constantdefinitionnotes
word_sizeThe second template parameter (w)The number of bits of each word in the state sequence.
state_sizeThe third template parameter (n)The number of elements in the state sequence (degree of recurrence).
shift_sizeThe fourth template parameter (m)The shift size used on twists to transform the values.
mask_bitsThe fifth template parameter (r)The number of bits that mark the separation point of words on each twist.
xor_maskThe sixth template parameter (a)The XOR mask applied as the linear function on each twist.
tempering_uThe seventh template parameter (u)The shift size of parameter u used in the tempering process of the generation algorithm.
tempering_dThe eighth template parameter (d)The XOR mask used as parameter d in the tempering process of the generation algorithm.
tempering_sThe ninth template parameter (s)The shift size of parameter s used in the tempering process of the generation algorithm.
tempering_bThe tenth template parameter (b)The XOR mask used as parameter b in the tempering process of the generation algorithm.
tempering_tThe eleventh template parameter (t)The shift size of parameter t used in the tempering process of the generation algorithm.
tempering_cThe twelfth template parameter (c)The XOR mask used as parameter c in the tempering process of the generation algorithm.
tempering_lThe thirteenth template parameter (l)The shift size of parameter l used in the tempering process of the generation algorithm.
initialization_multiplierThe fourteenth template parameter (f)The initialization multiplier used to seed the state sequence when a single value is used as seed.
default_seed5489uThe default seed used on construction or seeding.

See also