lundi 26 octobre 2015

Rolling multiple dice at the same time

I am currently using srand() in order to reset the seed at each method call, however the method was being called quicker than the refresh rate of the seed, therefore I used Sleep() in order to give the seed enough time to refresh and now I am stuck with a program that runs too slow. I was wondering if there is a way to get the result of multiple die, without calling Sleep() and without getting the same value on each die. The code in question:

int rollDice() {
    srand(time(NULL)); 
    Sleep(1100); //too slow, however any faster and the values repeat
    int x = (rand() % 6) + 1;
    return x;
} 




Aucun commentaire:

Enregistrer un commentaire