lundi 12 avril 2021

Re-initializing random distribution

Is it reasonable to expect that a distribution from <random> re-initialized before each next number request behaves the same way as if it was initialized once? In other words, does this:

std::default_random_engine generator;
int p[10]={};
for (int i=0; i<nrolls; ++i) {
 std::uniform_int_distribution<int> distribution(0,9);
 int number = distribution(generator);
 ++p[number];
} 

have the same distribution as that

std::uniform_int_distribution<int> distribution(0,9);
std::default_random_engine generator;
int p[10]={};
for (int i=0; i<nrolls; ++i) {
 int number = distribution(generator);
 ++p[number];
} 

I've checked that for uniform and normal distribution it empirically holds true. Can I expect it from every distribution in <random>?

Aucun commentaire:

Enregistrer un commentaire