![]() |
Home | Libraries | People | FAQ | More |
boost::random::mersenne_twister_engine
// In header: <boost/random/mersenne_twister.hpp> template<typename UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f> class mersenne_twister_engine { public: // types typedef UIntType ; // construct/copy/destruct (); (UIntType); template<typename It> (It &, It); template<typename SeedSeq> (SeedSeq &); // public member functions void (); void (UIntType); template<typename SeeqSeq> void (SeeqSeq &); template<typename It> void (It &, It); result_type (); template<typename Iter> void (Iter, Iter); void (boost::uintmax_t); // public static functions constexpr result_type (); constexpr result_type (); // friend functions template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, const mersenne_twister_engine &); template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > &, mersenne_twister_engine &); bool (const mersenne_twister_engine &, const mersenne_twister_engine &); bool (const mersenne_twister_engine &, const mersenne_twister_engine &); // public data members static const word_size; static const state_size; static const shift_size; static const mask_bits; static const UIntType xor_mask; static const tempering_u; static const UIntType tempering_d; static const tempering_s; static const UIntType tempering_b; static const tempering_t; static const UIntType tempering_c; static const tempering_l; static const UIntType initialization_multiplier; static const UIntType default_seed; static const UIntType parameter_a; static const output_u; static const output_s; static const UIntType output_b; static const output_t; static const UIntType output_c; static const output_l; static const bool has_fixed_range; };
Instantiations of class template mersenne_twister_engine model a pseudo-random number generator . It uses the algorithm described in
"Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator", Makoto Matsumoto and Takuji Nishimura, ACM Transactions on Modeling and Computer Simulation: Special Issue on Uniform Random Number Generation, Vol. 8, No. 1, January 1998, pp. 3-30.
![]() |
Note |
---|---|
The boost variant has been implemented from scratch and does not derive from or use mt19937.c provided on the above WWW site. However, it was verified that both produce identical output. |
The seeding from an integer was changed in April 2005 to address a weakness.
The quality of the generator crucially depends on the choice of the parameters. User code should employ one of the sensibly parameterized generators such as mt19937 instead.
The generator requires considerable amounts of memory for the storage of its state array. For example, mt11213b requires about 1408 bytes and mt19937 requires about 2496 bytes.
mersenne_twister_engine
public
construct/copy/destruct();
Constructs a
and calls mersenne_twister_engine
seed()
.
(UIntType value);
Constructs a
and calls mersenne_twister_engine
seed(value)
.
template<typename It> (It & first, It last);
template<typename SeedSeq> (SeedSeq & seq);
Constructs a mersenne_twister_engine
and calls seed(gen)
.
![]() |
Note |
---|---|
The copy constructor will always be preferred over the templated constructor. |
mersenne_twister_engine
public member functionsvoid ();
Calls seed(default_seed)
.
void (UIntType value);
Sets the state x(0) to v mod 2w. Then, iteratively, sets x(i) to (i + f * (x(i-1) xor (x(i-1) rshift w-2))) mod 2w for i = 1 .. n-1. x(n) is the first value to be returned by operator().
template<typename SeeqSeq> void (SeeqSeq & seq);
Seeds a mersenne_twister_engine
using values produced by seq.generate().
template<typename It> void (It & first, It last);
Sets the state of the generator using values from an iterator range.
result_type ();
Produces the next value of the generator.
template<typename Iter> void (Iter first, Iter last);
Fills a range with random values
void (boost::uintmax_t z);
Advances the state of the generator by z
steps. Equivalent to
mersenne_twister_engine
public static functionsconstexpr result_type ();
Returns the smallest value that the generator can produce.
constexpr result_type ();
Returns the largest value that the generator can produce.
mersenne_twister_engine
friend functionstemplate<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > & os, const mersenne_twister_engine & mt);
Writes a mersenne_twister_engine
to a std::ostream
template<typename CharT, typename Traits> CharT, Traits > & (CharT, Traits > & is, mersenne_twister_engine & mt);
Reads a mersenne_twister_engine
from a std::istream
bool (const mersenne_twister_engine & x_, const mersenne_twister_engine & y_);
Returns true if the two generators are in the same state, and will thus produce identical sequences.
bool (const mersenne_twister_engine & x_, const mersenne_twister_engine & y_);
Returns true if the two generators are in different states.