I would like to wrap the random number distributions from the C++11 standard library with simple functions that take as arguments the distribution's parameters and a generator instance. For example:
double normal(double mean, double sd, std::mt19937_64& generator)
{
static std::normal_distribution<double> dist;
return dist(generator, std::normal_distribution<double>::param_type(mean, sd));
}
I want to avoid any hidden state within the distribution object so that each call to this wrapper function only depends on the given arguments. (Potentially, each call to this function could take a different generator instance.) Ideally, I would make the distribution instance static const
to ensure this; however, the distribution's operator()
is not a const function, so this isn't possible.
My question is this: To ensure there is no hidden state within the distribution, is it 1) necessary and 2) sufficient to call reset()
on the distribution each time? For example:
double normal(double mean, double sd, std::mt19937_64& generator)
{
static std::normal_distribution<double> dist;
dist.reset();
return dist(generator, std::normal_distribution<double>::param_type(mean, sd));
}
(Overall, I'm confused about the purpose of the reset()
function for the random distributions... I understand why the generator would need to be reset/reseeded at times, but why would the distribution object need to be reset?)