Share via


variate_generator Class

Wraps an engine and a distribution.

template<class Engine, class Dist>
    class variate_generator {
public:
    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;
private:
    Engine eng;             // exposition only
    Dist dist;              // exposition only
    };

Parameters

  • Engine
    The type of the random engine.

  • Dist
    The type of the distribution.

Remarks

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.

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

variate_generator::distribution

variate_generator::distribution_type

variate_generator::engine

variate_generator::engine_type

variate_generator::engine_value_type

variate_generator::operator()

variate_generator::variate_generator

Other Resources

<random> Members