random numbers all different???

Reply

Join Date: Apr 2003
Posts: 1
Reputation: mynewdeadcat is an unknown quantity at this point 
Solved Threads: 0
mynewdeadcat mynewdeadcat is offline Offline
Newbie Poster

random numbers all different???

 
0
  #1
Apr 27th, 2003
int upper;


cout << "#s (4 - 9) ";
cin >> upper;

for (int count = 0; count < 4; count++)
{
int y;
srand((unsigned)time(0));
y = (rand()%upper)+1;
cout << y<< endl;
key[count] = y;
Sleep (1000);
}

this is my random number gen and i was wondering if there was a way to have it generate 4 different random numbers indtead of just four im basically either looking for something to change the rand so they all come out different or to change it over after the fact i thought it was easy you know just throw a loop in here with a if statment but when i do that it sends it into and infinate loop well thanks for you help
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member
 
0
  #2
Apr 27th, 2003
Remove your call to srand() from the loop and place it before the loop so that it's called just once.

If you're not sure why, take a look at the tutorial on random numbers.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC