public member function
explicit mersenne_twister_engine ( result_type val = default_seed );
template <class Sseq>
explicit mersenne_twister_engine ( Sseq& q );
Construct mersenne twister engine
Constructs a mersenne_twister_engine object, and initializes its internal state sequence to pseudo-random values.
The internal state sequence is seeded either applying a linear random generator on a single value (val) or using a seed sequence object (q).
- A seeding value. An entire state sequence is generated from this value using a linear random generator.
result_type is a member type, defined as an alias of the first class template parameter (UIntType).
default_seed is a member constant, defined as 5489u.
- A seed sequence object, such as an object of type seed_seq.
Sseq shall be a seed sequence class, with a generate member function.
// mersenne_twister_engine constructor
int main ()
// obtain a seed from the system clock:
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
// obtain a seed from the user:
std::cout << "Please, enter a seed: ";
std::seed_seq seed2 (str.begin(),str.end());
std::mt19937 g1 (seed1); // mt19937 is a standard mersenne_twister_engine
std::cout << "A time seed produced: " << g1() << std::endl;
std::mt19937 g2 (seed2);
std::cout << "Your seed produced: " << g2() << std::endl;
Please, enter a seed: Matsumoto and Nishimura
A time seed produced: 749725171
Your seed produced: 4255278487
Linear on state_size.