Share via


variate_generator::variate_generator

Constructs the generator.

variate_generator(engine_type eng0, distribution_type dist0);

Parameters

  • eng0
    The engine object to wrap.

  • dist0
    The distribution object to wrap.

Remarks

The constructor constructs an object whose stored value eng holds eng0 and whose stored value dist holds dist0.

Example

 

// std_tr1__random__variate_generator_construct.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::minstd_rand Myeng; 
typedef std::uniform_int<unsigned int> Mydist; 
typedef std::variate_generator<Myeng, Mydist> Myceng; 
int main() 
    { 
    Myeng eng0; 
    Mydist dist0; 
    Myceng ceng(eng0, dist0); 
    const Myceng::engine_type& eng = ceng.engine(); // get base engine 
    const Myceng::distribution_type& dist = 
        ceng.distribution(); // get distribution 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
    eng.min(); 
    dist.min(); 
 
    std::cout << "min == " << ceng.min() << std::endl; 
    std::cout << "max == " << ceng.max() << std::endl; 
 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
 
    return (0); 
    } 
 
min == 0
max == 9
a random value == 0
a random value == 6
a random value == 8

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

variate_generator Class

Other Resources

<random> Members