You need to initialize the random generator with a "truly random" (or at least unique) seed, and do it only once.
This is usually done with srand(time(NULL))
at the beginning.
Numbers generated by rand()
are not random, they are *pseudo*random: given the same seed, it will always return the same sequence. By default, I believe the initial seed is zero (however, it is for sure always the same between program runs - so without seeding you'll always get the same apparently random sequence every time).