jeudi 28 mai 2015

How many random numbers can std::uniform_real_distribution generate before losing randomness?

I am writing a c++ code for a Monte Carlo simulation. As such, I need to generate many numbers uniformly distributed between [0,1). I included the following code taken from here to generate my numbers:

// uniform_real_distribution
#include <iostream>
#include <random>

std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0.0,1.0);

int main()
{  
    double number = distribution(generator); //rnd number uniformly distributed between [0,1)
    return 0;
}

So every time I need a new number, I just call distribution(generator). I run my Monte Carlo simulation to get many sample results. The results should be normally distributed around the real mean (that is unknown). When I run a chi-square goodness-of-fit test to check if they are normally distributed, my sample results do not pass the test sometimes. The key word here is "sometimes", so this made me think that I called distribution(generator) too many times and in the end I lost randomness of the generated numbers. I am talking about 10^11 numbers generated in each simulation.

Could it be possible? What if I reset the distribution with distribution.reset() before I call it? Would that solve my problem?

Thanks for any suggestion you may have.




Aucun commentaire:

Enregistrer un commentaire