| Home | Libraries | People | FAQ | More

## Class template variate_generator

boost::variate_generator

## Synopsis

    // In header: <boost/random/variate_generator.hpp>

    template<typename Engine, typename Distribution>
    class variate_generator {
    public:
      // types
      typedef decorated_engine::base_type engine_value_type;
      typedef Engine                      engine_type;
      typedef Distribution                distribution_type;
      typedef Distribution::result_type   result_type;

      // construct/copy/destruct
      variate_generator(Engine, Distribution);

      // public member functions
      result_type operator()();
      template<typename T> result_type operator()(T);
      engine_value_type & engine();
      const engine_value_type & engine() const;
      distribution_type & distribution();
      const distribution_type & distribution() const;
      result_type min() const;
      result_type max() const;
    };

## Description

A random variate generator is used to join a random number generator together with a random number distribution. Boost.Random provides a vast choice of generators as well as distributions .

Instantations of class template `variate_generator` model a number generator .

The argument for the template parameter Engine shall be of the form U, U&, or U*, where U models a uniform random number generator . Then, the member engine_value_type names U (not the pointer or reference to U).

Specializations of `variate_generator` satisfy the requirements of CopyConstructible. They also satisfy the requirements of Assignable unless the template parameter Engine is of the form U&.

The complexity of all functions specified in this section is constant. No function described in this section except the constructor throws an exception.

### `variate_generator` public construct/copy/destruct

1.     variate_generator(Engine e, Distribution d);

   Constructs a `variate_generator` object with the associated uniform random number generator eng and the associated random distribution d.

   Throws: If and what the copy constructor of Engine or Distribution throws.

### `variate_generator` public member functions

1.     result_type operator()();

   Returns: distribution()(e)

   Notes: The sequence of numbers produced by the uniform random number generator e, se, is obtained from the sequence of numbers produced by the associated uniform random number generator eng, seng, as follows: Consider the values of `numeric_limits<T>::is_integer` for `T` both `Distribution::input_type` and `engine_value_type::result_type`. If the values for both types are true, then se is identical to seng. Otherwise, if the values for both types are false, then the numbers in seng are divided by engine().max()-engine().min() to obtain the numbers in se. Otherwise, if the value for `engine_value_type::result_type` is true and the value for `Distribution::input_type` is false, then the numbers in seng are divided by engine().max()-engine().min()+1 to obtain the numbers in se. Otherwise, the mapping from seng to se is implementation-defined. In all cases, an implicit conversion from `engine_value_type::result_type` to `Distribution::input_type` is performed. If such a conversion does not exist, the program is ill-formed.

2.     template<typename T> result_type operator()(T value);

   Returns: distribution()(e, value). For the semantics of e, see the description of operator()().

3.     engine_value_type & engine();

   Returns: A reference to the associated uniform random number generator.

4.     const engine_value_type & engine() const;

   Returns: A reference to the associated uniform random number generator.

5.     distribution_type & distribution();

   Returns: A reference to the associated random distribution.

6.     const distribution_type & distribution() const;

   Returns: A reference to the associated random distribution.

7.     result_type min() const;

   Precondition: distribution().min() is well-formed

   Returns: distribution().min()

8.     result_type max() const;

   Precondition: distribution().max() is well-formed

   Returns: distribution().max()