rand() returns same values when called within a single function

You shouldn’t call srand() before each call to rand(). Call it once – somewhere at the start of your program.

The problem is you restart the random generator so it starts to produce the very same pseudorandom sequence from the very same point.

Leave a Comment