Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Is there an easy way to program a string of unique random numbers?
I'm talking about, for example, a deck of cards. I know how to make a single random number, but how does one get 13 non-repeating random numbers without checking each new number against all the previously generated numbers and just keep getting random numbers until one works.
I just use simple programming languages.
5 Answers
- 1 decade agoFavorite Answer
you would have to check against the original, however you could start with an array containing all 13 numbers the randomly pic from it and at the same time remove it from the array repeating this 12 more times. the best practice is to use randomize and use the smallest increment of time possible as the seed value.
- 1 decade ago
The best way to do this is to make sure that you are not using the number directly, but are instead using it to make a decision that leads to a unique outcome.
For example, let's say you have 13 cards, in a stack. If you use a random number generator to select cards from that stack, you run the risk of selecting a card twice. Not good.
However, if you use the random number generator to split the stack, and take a card above (or below) the split point, then you will never have this problem.
All you need to know is the number of cards 'left' in the stack, and pick a random number (say) between 1 and 10. For the sake of simplicity let's assume that the split point is the middle.
If the random number is greater than 5, we take the card above the split. If it's lower than or equal to 5, we take the card below the split.
And that's really all there is to it! You can, as a refinement, move the split point to a random position, as well, to increase the chances of picking a card appropriately.
Have fun!
Best,
Guy
Source(s): http://computerprogramming.suite101.com/ - runFunningLv 61 decade ago
Most random generators are only psuedo random.
There are many techniques. An easy one ( and what I often use ) to generate a psuedo random number is to seed the random generator using the current milli second.
Good luck.
- BlackcompeLv 71 decade ago
its random man. youll have to check against the previous set, to know whether to generate a new one, if you do not want non-repeating random numbers.
- How do you think about the answers? You can sign in to vote the answer.
- Anonymous5 years ago
Well, it isn't random if you remove duplicates. But, that is what you need to do. You need to keep track of all the integers you've generated and if you get one that is a duplicate, throw it away and get another one.



