Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
variate_generator Class

variate_generator Class

Wraps an engine and a distribution.

template<class Engine, class Dist>
    class variate_generator {
    typedef Engine engine_type;
    typedef engine-value-type engine_value_type;
    typedef Dist distribution_type;
    typedef typename Dist::result_type result_type;
    variate_generator(engine_type eng0, distribution_type dist0);
    result_type operator()();
    template<class T>
        result_type operator()(T value);
    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;
    Engine eng;             // exposition only
    Dist dist;              // exposition only


The type of the random engine.


The type of the distribution.

The template class describes an object that holds an engine and a distribution and produces values by passing the wrapped engine object to the distribution object's operator().

The template argument Engine can be a type Eng, Eng*, or Eng&, where Eng is an engine. The type Eng is the underlying engine type. The corresponding object of type Eng is the the underlying engine object.

The template uses a wrapped engine to match the type of the values produced by the engine object to the type of values required by the distribution object. The wrapped engine's operator() returns values of type Dist::input_type, generated as follows:

if Engine::result_type and Dist::input_type are both integral types it returns eng(), converted to type Dist::input_type.

if Engine::result_type and Dist::input_type are both floating-point types it returns (eng() - eng.min()) / (eng.max() - eng.min()), converted to type Dist::input_type.

if Engine::result_type is an integral type and Dist::input_type is a floating-point type it returns (eng() - eng.min()) / (eng.max() - eng.min() + 1), converted to type Dist::input_type.

if Engine::result_type is a floating-point type and Dist::input_type is an integral type it returns ((eng() - eng.min()) / (eng.max() - eng.min()) * std::numeric_limits<Dist::input_type>::max(), converted to type Dist::input_type.

Header: <random>

Namespace: std

Community Additions

© 2015 Microsoft