I want to create a class that will return a random number whenever I call it. But when I put it into a loop it returns the same random number each time. I am seeding it once but it still returns the same one over and over again. Its only when I close out of the program and open it again itll be different. Any help would be much appreciated.
**EDIT
When I cant see how I am calling it every time.
RadomGenerator rg = new...
for(int i =0; i<10; i++){
rg.createRandomNumber(1,5);}
Is this not instansiating the seed only once then calling the method createRandomNumber several times?
RandomGenerator::RandomGenerator()
{
seed = time(0);
}
int RandomGenerator::createRandomNumber(int start, int end)
{
std::function<int()> randomNumber = std::bind(std::uniform_int_distribution<int>(start,end),
mt19937(seed));
qDebug()<< "result" << randomNumber() ;
return randomNumber();
}
Aucun commentaire:
Enregistrer un commentaire