Using a 6-sided Die to Generate a Random Number From 1 to 7Date: 12/23/2007 at 11:34:38 From: James Subject: Generate random 1-7 number given a single six-sided die During playing a card game I am asked to select a card at random from my opponent's hand of 7 cards. I have only a 6-sided die. What reasonable amount of time and number of steps can I take in order to ensure a random selection of 1 card? I would assign 1 to the left most card (with respect to me) in my opponent's hand and continue to the right assigning numbers 2-7. If an opponent's hand has less than 6 cards, I can just re-roll on a number that would not correspond to a card. However I can not do such a thing for 7 cards. If I assign 1-5 for the first through fifth cards in my opponent's hand I can't assign 6 to the last card and then roll the die again to determine which to select (even for 6 and odd for 7) since that would not yield a random result. I thought about rolling the 6-sided die first and even and odd would then tell me which half to select from. For example roll 3:odd, take the last four cards. Then roll the die to determine which of the last four to take from with 5-6 being re-rolls. But I do not know if that would give a skew. Date: 12/24/2007 at 13:16:25 From: Doctor Tom Subject: Re: Generate random 1-7 number given a single six-sided die Hi James, There are a bunch of options. Here's an easy one: roll the die twice, keeping track of the first and second roll. There are 36 outcomes: (1,1), (1,2), (1,3), ..., (6,6) (The first number is what you got on the first roll; the second is what you got on the second.) If you get a (6,6), just re-roll the die twice again until you get a non-(6,6). Now there are 35 equally-likely outcomes, so divide them into 7 groups of 5 corresponding to the 7 choices among which you want to choose. Here's an easy calculation that will do it. Suppose you roll a (x, y) with x = number on first roll and y = number on second roll. First calculate the following number: N = 6(x-1) + y. These possible values of N (all equally likely) will run from 1 to 35 (assuming you disallow a (6, 6)), including each value exactly once. Then divide the number N by 7 and look only at the remainder. For example, if you rolled a (4, 5), the number N would be 6(4-1)+5 = 23. Divide 7 into 23 and it goes in 3 times with a remainder of 2. If the number is exactly divisible by 7, the remainder is zero, so there are 7 equally-likely possible outcomes for the remainder: 0, 1, 2, 3, 4, 5 and 6. Note that this solution is not perfect in the sense that there is no upper bound to the number of times you'd need to roll a pair of dice to obtain a non-(6,6), but in the practical world, even getting two (6,6) outcomes in a row will only happen less than one time in a thousand. Obviously you're willing to do something like that, since you talked about getting one of 5 outcomes by rolling the die and re-rolling if you get a 6. - Doctor Tom, The Math Forum http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/