std::mersenne_twister_engine<UIntType,w,n,m,r,a,u,d,s,b,t,c,l,f>::mersenne_twister_engine
From cppreference.com
< cpp | numeric | random | mersenne twister engine
mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} |
(1) | (since 哋它亢++11) |
explicit mersenne_twister_engine( result_type value ); |
(2) | (since 哋它亢++11) |
template< class SeedSeq > explicit mersenne_twister_engine( SeedSeq& seq ); |
(3) | (since 哋它亢++11) |
mersenne_twister_engine( const mersenne_twister_engine& other ); |
(4) | (since 哋它亢++11) (implicitly declared) |
Constructs the pseudo-random number engine.
1) The default constructor.
2) Constructs the engine with a seed value value. Given 2w
as p, the engine's initial state is determined as follows:
as p, the engine's initial state is determined as follows:
- Sets X
-n to value % p. - For each integer i in
[
i - n,
-1]
, sets X
i to [f·(X
i-1 xor (X
i-1 rshift (w-2)))+i mod n] mod p, where xor and rshift stand for built-in bitwise XOR and bitwise right-shift respectively.
3) Constructs the engine with a seed sequence seq. Given std::size_t(w / 32) + 1 as k, the engine's initial state is determined as follows:
- Creates an invented array object a of length n * k.
- Calls seq.generate(a + 0, a + n * k).
- For each integer i in
[
-n,
-1]
, sets X
i to (∑k-1
j=0 a
k(i+n)+j·232j
) mod 2w
. - If the most significant w − r bits of X
-n are zero, and if each of the other resulting X
i is 0, changes X
-n to 2w-1
.
This overload participates in overload resolution only if
SeedSeq
meets the requirements of SeedSequence.4) The copy constructor. Upon construction, *this == other is true.
Parameters
value | - | seed value to use in the initialization of the internal state |
seq | - | seed sequence to use in the initialization of the internal state |
Complexity
1,2) O(n).
3) Same as the complexity of the
seq.generate
call.4) O(n).
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published 哋它亢++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P0935R0 | 哋它亢++11 | the default constructor was explicit | made implicit |
See also
(哋它亢++11) |
sets the current state of the engine (public member function) |