| Home | Libraries | People | FAQ | More

## Class template mersenne_twister_engine

boost::compute::mersenne_twister_engine — Mersenne twister pseudorandom number generator.

## Synopsis

    // In header: <boost/compute/random/mersenne_twister_engine.hpp>

    template<typename T>
    class mersenne_twister_engine {
    public:
      // types
      typedef T result_type;

      // construct/copy/destruct
      explicit mersenne_twister_engine(command_queue &,
                                       result_type = default_seed);
      mersenne_twister_engine(const mersenne_twister_engine< T > &);
      mersenne_twister_engine< T > &
      operator=(const mersenne_twister_engine< T > &);
      ~mersenne_twister_engine();

      // public member functions
      void seed(result_type, command_queue &);
      void seed(command_queue &);
      template<typename OutputIterator>
        void generate(OutputIterator, OutputIterator, command_queue &);
      template<typename OutputIterator, typename Function>
        void generate(OutputIterator, OutputIterator, Function, command_queue &);
      void discard(size_t, command_queue &);

      // public data members
      static const T default_seed;
      static const T n;
      static const T m;
    };

## Description

### `mersenne_twister_engine` public construct/copy/destruct

1.     explicit mersenne_twister_engine(command_queue & queue,
                                        result_type value = default_seed);

   Creates a new `mersenne_twister_engine` and seeds it with `value`.

2.     mersenne_twister_engine(const mersenne_twister_engine< T > & other);

   Creates a new `mersenne_twister_engine` object as a copy of `other`.

3.     mersenne_twister_engine< T > &
       operator=(const mersenne_twister_engine< T > & other);

   Copies `other` to `*this`.

4.     ~mersenne_twister_engine();

   Destroys the `mersenne_twister_engine` object.

### `mersenne_twister_engine` public member functions

1.     void seed(result_type value, command_queue & queue);

   Seeds the random number generator with `value`.

   If no seed value is provided, `default_seed` is used.

   Parameters: |
   `queue` | command queue to perform the operation
   `value` | seed value for the random-number generator

2.     void seed(command_queue & queue);

   This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

3.     template<typename OutputIterator>
         void generate(OutputIterator first, OutputIterator last,
                       command_queue & queue);

   Generates random numbers and stores them to the range [`first`, `last`).

4.     template<typename OutputIterator, typename Function>
         void generate(OutputIterator first, OutputIterator last, Function op,
                       command_queue & queue);

   Generates random numbers, transforms them with `op`, and then stores them to the range [`first`, `last`).

5.     void discard(size_t z, command_queue & queue);

   Generates `z` random numbers and discards them.