Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template mersenne_twister_engine

boost::random::mersenne_twister_engine

Synopsis

// 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  ;

  // construct/copy/destruct
  ();
  ();
  template<typename It> (, );
  template<typename SeedSeq> ();

  // public member functions
   ();
   ();
  template<typename SeeqSeq>  ();
  template<typename It>  (, );
   ();
  template<typename Iter>  (, );
   ();

  // public static functions
   ();
   ();

  // friend functions
  template<typename CharT, typename Traits> 
     
    (, 
               mersenne_twister_engine &);
  template<typename CharT, typename Traits> 
     
    (, 
               mersenne_twister_engine &);
   (mersenne_twister_engine &, 
                  mersenne_twister_engine &);
   (mersenne_twister_engine &, 
                  mersenne_twister_engine &);

  // public data members
  static  word_size;
  static  state_size;
  static  shift_size;
  static  mask_bits;
  static  xor_mask;
  static  tempering_u;
  static  tempering_d;
  static  tempering_s;
  static  tempering_b;
  static  tempering_t;
  static  tempering_c;
  static  tempering_l;
  static  initialization_multiplier;
  static  default_seed;
  static  parameter_a;
  static  output_u;
  static  output_s;
  static  output_b;
  static  output_t;
  static  output_c;
  static  output_l;
  static  has_fixed_range;
};

Description

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] 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

  1. ();

    Constructs a mersenne_twister_engine and calls seed().

  2. ( value);

    Constructs a mersenne_twister_engine and calls seed(value).

  3. template<typename It> ( first,  last);
  4. template<typename SeedSeq> ( seq);

    Constructs a mersenne_twister_engine and calls seed(gen).

    [Note] Note

    The copy constructor will always be preferred over the templated constructor.

mersenne_twister_engine public member functions

  1.  ();

    Calls seed(default_seed).

  2.  ( 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().

  3. template<typename SeeqSeq>  ( seq);

    Seeds a mersenne_twister_engine using values produced by seq.generate().

  4. template<typename It>  ( first,  last);

    Sets the state of the generator using values from an iterator range.

  5.  ();

    Produces the next value of the generator.

  6. template<typename Iter>  ( first,  last);

    Fills a range with random values

  7.  ( z);

    Advances the state of the generator by z steps. Equivalent to

mersenne_twister_engine public static functions

  1.  ();

    Returns the smallest value that the generator can produce.

  2.  ();

    Returns the largest value that the generator can produce.

mersenne_twister_engine friend functions

  1. template<typename CharT, typename Traits> 
       
      ( os, 
                 mersenne_twister_engine & mt);

    Writes a mersenne_twister_engine to a std::ostream

  2. template<typename CharT, typename Traits> 
       
      ( is, 
                 mersenne_twister_engine & mt);

    Reads a mersenne_twister_engine from a std::istream

  3.  (mersenne_twister_engine & x_, 
                    mersenne_twister_engine & y_);

    Returns true if the two generators are in the same state, and will thus produce identical sequences.

  4.  (mersenne_twister_engine & x_, 
                    mersenne_twister_engine & y_);

    Returns true if the two generators are in different states.


PrevUpHomeNext