vendredi 31 juillet 2020

How to generate random numbers on Windows that aren't all the same?

I was trying to generate two random integers with one greater than the other.

int lower = 1;
int upper = 10000;
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<std::mt19937::result_type> uni(lower, upper);
auto min = uni(rng);
auto max = min + uni(rng);
assert(("max not greater than min", max > min));
cout << "min: " << min << "max: " << max << endl;

I noticed I kept getting the exact same results. I compile with g++ TestRandomWorks.cpp -o TestRandomWorks.exe -pedantic -Wall and get no errors. I think this is the same bug from Why do I get the same sequence for every run with std::random_device with mingw gcc4.8.1? though it seems rather large to have been ignored. How can I upgrade MSYS2? I tried running the commands pacman -Syu and pacman -Su in its terminal but nothing changed. Is there any alternatives or work around? I just want to generate random numbers on Windows.




Aucun commentaire:

Enregistrer un commentaire