srand
's purpose is to initialize the random number generator.
Its parameter is called a seed. If you give the same seed twice, you can expect the random number generator (subsequent calls to rand()
) to return the same sequence of "random" numbers.
In your case you're constantly calling srand with the same value (until the second changes), so rand() will always return you the same value.
You just need to call srand
once.