lundi 26 juin 2017

"Random" numbers are always increasing and not very random

I am using the below code to generate five random numbers between 1 and 20. However, the values chosen are always ascending and do not appear random. I'd also like to increase the entropy across the function being called multiple times. For example, the number 2 appears nearly every time per method call. How can I improve the randomness?

// Gets called multiple times
void x(){

    std::random_device rd;
    std::mt19937 generator(rd());
    std::uniform_int_distribution<int> dist2(1, 20);

    for(int i = 0; i < 5; ++i)
    {
        int y = dist2(generator);
    }
}




Aucun commentaire:

Enregistrer un commentaire