Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Boost Random Number Library Variate Generator

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 .

Class template variate_generator

Synopsis

#include <boost/random/variate_generator.hpp>

template<class Engine, class Distribution>
class variate_generator
{
public:
  typedef Engine engine_type;
  typedef Distribution distribution_type;
  typedef typename Distribution::result_type result_type;

  variate_generator(Engine e, Distribution d);

  result_type operator()();
  template<class T>
  result_type operator()(T value);
  
  engine_value_type& engine();
  const engine_value_type& engine() const;

  result_type min() const;
  result_type max() const;
};

Description

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(engine_type eng, distribution_type d)

Effects: 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.

    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.

    template<class T> result_type operator()(T value)

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

    engine_value_type& engine()

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

    const engine_value_type& engine() const

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

    distribution_type& distribution()

Returns: A reference to the associated random distribution.

    const distribution_type& distribution() const

Returns: A reference to the associated random distribution.

    result_type min() const

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

    result_type max() const

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


Valid HTML 4.01 Transitional

Revised 05 December, 2006

Copyright © 2003-2004 Jens Maurer

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)