I am currently stuck at generating random numbers during runtime. In Java, I just call Math.random() and I'm pretty much done (I just need a simple RNG). In C++, I have tried several ways to generate random numbers and always end up getting the same.
Currently, I am using the following method to get a random number between MIN and MAX:
unsigned int getRandomNumber(int min, int max){
std::mt19937 mt(1729);
std::uniform_int_distribution<int> dist(min, max);
return dist(mt);
}
I have an object that calls this function in its constructor and assigns the value returned to an attribute. I currently create five instances of this object and the random number is always the same. Setting a big range (1 - 1000) does not change this. The number is always the same. Security is not a concern, it is an extremely simple application.
Aucun commentaire:
Enregistrer un commentaire