With the same seed, the random number generator will produce the exact same sequence of numbers.
What we want is a seed that is "random", or at least different every time, so that the sequence of random numbers is different every time.
The srand()
function uses the system clock as a seed. As mentioned in a comment, if you call srand()
multiple times in this one second period and then get a random number, you'll get the same "random" number every time.
Calling srand()
outside of a loop is no different, except for the fact that it might be called with at least one second between each call. This means the seed is different, and the numbers generated are different.
Also, as mentioned in another comment, it's usually only necessary to seed the random number generator once at the beginning of your program. You might not want to do this if for some reason you want to generate the same sequence of numbers multiple times.