• Advertisement

Archived

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

random

This topic is 5859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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

  • Advertisement