in reply to random pairs

The easiest if not the only way to obtain “random but unique draws” is always going to be to do what we do in real life:   use a deck of cards.   Create a list of 0..99 and then List::Util::shuffle that list ... quite literally like shuffling a deck of cards and then using it just as you do use a deck of cards in real life.   You will shift the next number off the front of the list, and if you don’t like that one, simply push it onto the end and shift another.   Exactly like putting the card on the bottom of the deck and drawing another top-card.   (If it’s the same value, then the queue has degenerated to only one entry and you’re screwed ... you do need to test for that case and die.   Although the odds of this happening are astronomically tiny, Murphy’s Law decrees that it will happen during your first and/or your most important demo.)

The odds are 99 to 1 that the number you draw will be acceptable, so you can simply loop through the list so-far to see if for any reason the number you have selected is disqualified.

another.

Replies are listed 'Best First'.
Re^2: random pairs
by CountZero (Bishop) on Jul 14, 2012 at 11:51 UTC
    shuffle is not the solution for this problem as it adds the unnecessary constraint that you should have no repeat from the set you shuffle.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics