943,473 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 9477
  • C++ RSS
Apr 27th, 2003
0

random numbers all different???

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mynewdeadcat is offline Offline
1 posts
since Apr 2003
Apr 27th, 2003
0
Re: random numbers all different???
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.
Bob
Team Colleague
Reputation Points: 15
Solved Threads: 2
Junior Poster
Bob is offline Offline
129 posts
since Feb 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: 3D GameStudio
Next Thread in C++ Forum Timeline: What Language is used in software like Adobe Photoshop?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC