The random number generator is completely deterministic; it will always output the same sequence of numbers for any given seed. srand()
seeds the random number generator. So by calling srand()
with the time immediately before each call to rand()
, and since your loops will take less than a second to execute, you'll always get the same random number (or maybe two if the time happens to change in the middle).
Try calling srand()
once before entering the loops.