srand
is meant to initialize the generator. You are supposed to initialize it once e.g. at the start of the program. Then call rand
.
Now you are initializing it every time you call the function. The reason why it is the same is because you supply the same argument twice for srand
. time(0)
returns the number of seconds since epoch till current time.
Basically you restart the generator for each subsequent call to the same state in every second. If you let it run for a span of 3 seconds you would see 3 different groups of values.
Also your formula is slightly wrong. You forgot to shift it by min.
rand()%(max-min+1)+min
Also if you work with c++
you might take a suggestion from FreeNickname and use c++
specific features.