View Single Post
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: C++ Random Numbers

 
0
  #8
Dec 15th, 2004
how can i make it where numbers can't repeat themselves
one way is to track what numbers are generated and save them in an array for instance. then check back to see if it is already generated.... IMHO if you have a range of over 50 then the numbers are going to still be random and its unlikely to get repeats. you could always get two random numbers in succession and multiply / add / whatever so that the combined numbers vary a bit more.

is there any code that you can put in names nd generate them in random order
put names in an array, generate random numbers from 0 to the size of the array - 1. make sure of no repeats and then store the numbers in a separate array so you might have:

"Bill"
"Bob"
"James"
"Chris"
"Thomas"

so you would generate numbers from 0 to 4 and might get:

3
1
4
0
2

in a separate array. Then copy across from the string array the string at the index specified by the second array. Then it becomes:

"Chris"
"Bob"
"Thomas"
"Bill"
"James"

Hope this helps
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool: