x**8 发帖数: 1939 | 1 我做了一个rand5 7次,然后再 %7 + 1,
这个我算了一下,基本均匀,但是不完全均匀,
这个可以吗?
取得1到7的次数分别为:
11177
11172
11158
11144
11144
11158
11172
大侠请指点! | t**a 发帖数: 33 | 2 Think about rand2 to rand3 firstly:
throw twice.
11=1
12=2
21 =3
22 rethrow
The left part is like binary number.
rand5 to rand7 can also work by throwing twice, you have 25 candidates, make
use of the first 21 to reduce the possibility of rethrow. | x**8 发帖数: 1939 | 3 多谢!
你这办法好,
我就没想到可以rethrow,嗯,
make
【在 t**a 的大作中提到】 : Think about rand2 to rand3 firstly: : throw twice. : 11=1 : 12=2 : 21 =3 : 22 rethrow : The left part is like binary number. : rand5 to rand7 can also work by throwing twice, you have 25 candidates, make : use of the first 21 to reduce the possibility of rethrow.
|
|