lundi 26 octobre 2015

C++ How can I set the parameter of a `std::exponential_distribution` object?

C++ Standard Library - Random Number Generation and Distributions: How can I set the parameter of the exponential distribution?

I have a program which requires exponentially distributed random numbers. I am using the C++11 Random Numbers and Distributions Library support.

I have a distribution: std::exponential_distribution<double> exp_dis(lambda);

lambda is any value to begin with. 0.0 or 1.0 are okay values to use.

I refer to this distribution in a thread function using a pointer. (I have an independent distribution for each thread function to avoid data race conditions.)

The value of lambda is computed within a loop, and can change each time the loop is executed.

Therefore I would like to know how the value of the parameter lamda can be "set" within the exponential distribution.

From some quick searches, I think I should be able to do this using the member function param(), but I can't figure out the exact syntax to use.

This doesn't work:

// Pointer to exponential distribution object
exp_dis_p->param(lambda);




Aucun commentaire:

Enregistrer un commentaire