mersenne_twister::mersenne_twister

Constructs the engine.

explicit mersenne_twister(unsigned long x0 = default_seed);
template<class Gen>
    mersenne_twister(Gen& gen);
mersenne_twister(const mersenne_twister& right);
mersenne_twister(mersenne_twister& right);

Parameters

  • x0
    The seed value.

  • Gen
    The type of the seed generator.

  • gen
    The seed generator.

  • right
    A mersenne_twister object.

Remarks

The first constructor constructs a mersenne_twister object and initializes it by calling seed(x0). The second constructor constructs a mersenne_twister object and initializes it by calling seed(gen). The third and fourth constructors construct a mersenne_twister object by copying a mersenne_twister object.

Example

 

// std_tr1__random__mersenne_twister_construct.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::tr1::minstd_rand Myeng; 
typedef std::tr1::mersenne_twister<unsigned int, 32, 624, 
    397, 31, 0x9908b0df, 11, 7, 0x9d2c5680, 
    15, 0xefc60000, 18> Myceng;  // same as mt19937 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "W == " << Myceng::word_size << std::endl; 
    std::cout << "N == " << Myceng::state_size << std::endl; 
    std::cout << "M == " << Myceng::shift_size << std::endl; 
    std::cout << "R == " << Myceng::mask_bits << std::endl; 
    std::cout << "A == " << Myceng::parameter_a << std::endl; 
    std::cout << "U == " << Myceng::output_u << std::endl; 
    std::cout << "S == " << Myceng::output_s << std::endl; 
    std::cout << "B == " << Myceng::output_b << std::endl; 
    std::cout << "T == " << Myceng::output_t << std::endl; 
    std::cout << "C == " << Myceng::output_c << std::endl; 
    std::cout << "L == " << Myceng::output_l << std::endl; 
 
    std::cout << "min == " << ceng.min() << std::endl; 
    std::cout << "max == " << ceng.max() << std::endl; 
 
    ceng.seed(); // reseed base engine 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
 
    Myceng ceng2(eng); // construct with generator 
    ceng2.seed(eng);  // seed with generator 
 
    Myceng ceng3(5UL);  // construct with unsigned long seed 
    ceng3.seed(5UL);  // seed with unsigned long 
 
    return (0); 
    } 
 

W == 32 N == 624 M == 397 R == 31 A == 2567483615 U == 11 S == 7 B == 2636928640 T == 15 C == 4022730752 L == 18 min == 0 max == 4294967295 a random value == 3499211612 a random value == 581869302 a random value == 3890346734

Requirements

Header: <random>

Namespace: std::tr1

See Also

Reference

<random>

mersenne_twister Class

mersenne_twister::seed