第一次 3 or 4 ===> 3 5 or 6 ===> 5 1 then roll one more time: 1 or 3 or 4 ===> 1 2 or 5 or 6 ====> 4 2 then roll one more time: 1 or 3 or 4 ===> 2 2 or 5 or 6 ====> 6
【在 k*******a 的大作中提到】 : 第一次 3 or 4 ===> 3 : 5 or 6 ===> 5 : 1 then roll one more time: 1 or 3 or 4 ===> 1 : 2 or 5 or 6 ====> 4 : 2 then roll one more time: 1 or 3 or 4 ===> 2 : 2 or 5 or 6 ====> 6
g*2
6 楼
use permutations (permutations are uniformly distributed). here you can use permutations of 3 unique numbers, which have 6 patterns. just let each pattern to represent one number.
【在 g******2 的大作中提到】 : use permutations (permutations are uniformly distributed). : here you can use permutations of 3 unique numbers, which have 6 patterns. : just let each pattern to represent one number.
One way is to use one fixed set, say 1,2,3 and then use all permutations of it. Every time you roll the die 3 times, and discard any other patterns. A better way is to use all sets (6 choose 3 -> 20). Then you can create a map of permutation to number (1-6). Also discard any other patterns. A more efficient way might be to create uniform 0,1 function first. Here you can also use permutation: roll a die twice, 0 if first roll < second roll and 1 if first roll > second roll. discard ties. Then it's just a problem of generating random numbers from uniform {0,1} function, which is very simple (binary number generating).