normal_distribution::operator()

Returns a random value.

template<class Engine>
    result_type operator()(Engine& eng);
template<class Engine>
    result_type operator()(Engine& eng,
        const param_type& par0);

Engine

The type of the random engine.

eng

The random engine.

par0

The parameter package used as a source for the random value.

The first member function uses the engine eng as a source of uniformly distributed random values and returns values with a probability density of pr(x) = 1 / (√(2 * pi) * stored_sigma) * (e)^(-(x - stored_mean)2 / (2 * stored_sigma^2)).

The second member function behaves the same, except that it uses the parameters stored in par0.

 

// std_tr1__random__normal_distribution_operator_fn.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::ranlux64_base_01 Myeng; 
typedef std::normal_distribution<double> Mydist; 
int main() 
    { 
    Myeng eng; 
    Mydist dist(1.5, 2.0); 
    Mydist::input_type engval = eng(); 
    Mydist::result_type distval = dist(eng); 
 
    distval = distval;  // to quiet "unused" warnings 
    engval = engval; 
 
    std::cout << "mean == " << dist.mean() << std::endl; 
    std::cout << "sigma == " << dist.sigma() << std::endl; 
 
    dist.reset(); // discard any cached values 
    std::cout << "a random value == " << dist(eng) << std::endl; 
    std::cout << "a random value == " << dist(eng) << std::endl; 
    std::cout << "a random value == " << dist(eng) << std::endl; 
 
    return (0); 
    } 
 
mean == 1.5
sigma == 2
a random value == 0.0275648
a random value == 0.0738393
a random value == 4.47125

Header: <random>

Namespace: std

Community Additions

ADD
Show: