Archived

This topic is now archived and is closed to further replies.

gamesrme

random

Recommended Posts

gamesrme    122
I am using this: code starts here //////////////////////////////////// /////////////////////////// #include #include #include void main() { for(int j=0; j<10; j++) { srand((unsigned int) time(0)); int i = rand() % 100; // random number between 0 and 99 int j = rand() % 5; // random number between 0 and 4 cout<

Share this post


Link to post
Share on other sites
OldGuy    122
Move the call to srand out of the loop; do it right before the loop. What is happening is that the program is executing very quickly, and you''re calling srand with the same number (time(0) is returning the same number). That resets the random number generator back to the same initial seed, yielding the same stream of random numbers.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
or replace srand();

with

srand(GetTickCount());


It would still be better to just move the call out of the loop. Even with GetTickCount() you''ll still probably get the same values (if your loop runs fast enough).

Share this post


Link to post
Share on other sites