mersenne_twister_engine Class
Generates a high quality random sequence of integers based on the Mersenne twister algorithm.
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;
Parameters
UIntType
The unsigned integer result type. For possible types, see <random>.W
Word size. Size of each word, in bits, of the state sequence. Precondition: 2u < W ≤ numeric_limits<UIntType>::digitsN
State size. The number of elements (values) in the state sequence.M
Shift size. The number of elements to skip during each twist. Precondition: 0 < M ≤ NR
Mask bits. Precondition: R ≤ WA
XOR mask. Precondition: A ≤ (1u<<W) - 1uU, S, T, L
Tempering shift parameters. Used as shift values during scrambling (tempering). Precondition: U,S,T,L ≤ WD, B, C
Tempering bit mask parameters. Used as bit mask values during scrambling (tempering). Precondition: D,B,C ≤ (1u<<W) - 1uF
Initialization multiplier. Used to help with initialization of the sequence. Precondition: F ≤ (1u<<W) - 1u
Members
mersenne_twister_engine::mersenne_twister_engine |
mersenne_twister_engine::min |
mersenne_twister_engine::discard |
mersenne_twister_engine::operator() |
mersenne_twister_engine::max |
mersenne_twister_engine::seed |
default_seed is a member constant, defined as 5489u, used as the default parameter value for mersenne_twister_engine::seed and the single value constructor. |
For more information about engine members, see <random>.
Remarks
This template class describes a random number engine, returning values on the closed interval [0, 2W - 1]. It holds a large integral value with W * (N - 1) + R bits. It extracts W bits at a time from this large value, and when it has used all the bits it twists the large value by shifting and mixing the bits so that it has a new set of bits to extract from. The engine's state is the last NW-bit values used if operator() has been called at least N times, otherwise the MW-bit values that have been used and the last N - M values of the seed.
The generator twists the large value that it holds by using a twisted generalized feedback shift register defined by shift values N and M, a twist value R, and a conditional XOR-mask A. Additionally, the bits of the raw shift register are scrambled (tempered) according to a bit-scrambling matrix defined by values U, D, S, B, T, C, and L.
The template argument UIntType must be large enough to hold values up to 2W - 1. The values of the other template arguments must satisfy the following requirements: 2u < W, 0 < M, M ≤ N, R ≤ W, U ≤ W, S ≤ W, T ≤ W, L ≤ W, W ≤ numeric_limits<UIntType>::digits, A ≤ (1u<<W) - 1u, B ≤ (1u<<W) - 1u, C ≤ (1u<<W) - 1u, D ≤ (1u<<W) - 1u, and F ≤ (1u<<W) - 1u.
Although you can construct a generator from this engine directly, it is recommended you use one of the predefined typedefs in the following table.
Name |
Description |
---|---|
mt19937 |
32-bit Mersenne twister engine (Matsumoto and Nishimura, 1998).
|
mt19937_64 |
64-bit Mersenne twister engine (Matsumoto and Nishimura, 2000).
|
For detailed information about the Mersenne twister algorithm, see the Wikipedia article Mersenne twister.
Example
For a code example, see <random>.
Requirements
Header: <random>
Namespace: std