Random numbers in C

Call srand() outside of the loop. You are reseeding it every iteration.

srand() seeds the random number generator so you get a different sequence of random numbers depending on the input. Your loop runs very fast, so the call to time(NULL) always returns the same value. You are resetting to the same random sequence with every iteration. As a general rule, only call srand() once in your program.

Leave a Comment