This comment, which states:
srand(time(0));
I would put this line as the first line in main() instead if calling it multiple times (
The seed determines what random numbers will be generated, in order, i.e. srand(1)
, will always generate the same number on the first call to rand()
, the same on the second call to rand()
and so on.
In other words, if you re-seeded with the same seed before each rand()
invocation, you'd generate the same random number every single time.
So successive seeding with time(0)
, during a single second, will mean all your random numbers after re-seeding are actually the same number.