dimanche 27 mai 2018

Rand() C after a while, generate always same values in decreasing order [duplicate]

This question already has an answer here:

I'm trying to generate random values between 0 and 3 with the following code. The problem is that after generating random values for the first 5-6 times, then it starts generating all the times in the following order: 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0 and then again 3, 3, 3, 2, 2, 2, 1, etc etc. Is there a way to avoid this and to generate COMPLETELY random this numbers?

srand(time(NULL));
i=rand()%4;
while(//condition is not verified//){

    srand(time(NULL));
    i=rand()%4;

}




Aucun commentaire:

Enregistrer un commentaire