• Advertisement


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

Random Number Generation....

This topic is 5997 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

Hi all, I am working on a small program and have run in to a problem. I am using this code: #define MAX 99 int main() {...} int Roll() { srand( (unsigned)time( NULL ) ); roll = rand()%MAX+1; cout << roll; // this line only for testing return roll; } to generate a random number. Where I am using it is inside a for loop that is also working. The problem I am having and it is more than likely my own stupidity, is the program goes through the cycles so fast it is returning duplicate numbers. I included a Sleep(500); to test it and it would only send back 2 of the same number before getting a new random number. My question is this, is there another way to seed the rand that will return random integers? Thanks in advance for any help. /* GRELLIN */

Share this post

Link to post
Share on other sites

  • Advertisement