I have a randomly generated number in a while
loop. Since I seed it using time(NULL)
when I run it I get a stream of similar results, while I would like it to be more "heterogeneous".
Here's the function:
while(1) {
srand((unsigned int) time(NULL)); // Seed
double chance = random() / (double) RAND_MAX;
if (chance <= 0.95)
printf("All ok.\n");
else
printf("ERROR\n");
}
For example the result of this would look like:
...
All ok.
All ok.
All ok.
All ok.
All ok.
ERROR
ERROR
ERROR
ERROR
ERROR
All ok.
All ok.
All ok.
All ok.
All ok.
...
How can I make the results be more independent from each other?
Aucun commentaire:
Enregistrer un commentaire