#### Archived

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.

## 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 on other sites
Don''t continuously seed the random number generator:
// insert your Roll() definition here.int main( .. ){  srand((unsigned)time(NULL));  ...  while( condition)  {    ...    r = Roll();    ...  }}

##### Share on other sites
Thanks so much! Now I can put the rest of my Tylenol away!

/* GRELLIN */