Read about srand.
If you seed the random number generator with the same value, you get the same sequence.
And for the duration of your program, time(0) likely doesn't change.