t*****y 发帖数: 31 | 1 利用能生成1-6随机整数的函数,如何构造生成1-7随机整数的函数。
怎么做呢? 谢谢 | s*x 发帖数: 3328 | 2 生成7个随机数,然后除以六。
【在 t*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 利用能生成1-6随机整数的函数,如何构造生成1-7随机整数的函数。 : 怎么做呢? 谢谢
| t*****y 发帖数: 31 | | a**********s 发帖数: 588 | 4 generate 1-6 twice, then map pairs to 1-7:
(1, 1) .... (1, 5) --------> 1
(1, 6) .... (2, 4) --------> 2
(2, 5) .... (3, 3) --------> 3
(3, 4) .... (4, 2) --------> 4
(4, 3) .... (5, 1) --------> 5
(5, 2) .... (5, 6) --------> 6
(6, 1) .... (6, 5) --------> 7
(6, 6) -------------------> do it again | t*****y 发帖数: 31 | 5 make sense
谢谢美女!
【在 a**********s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : generate 1-6 twice, then map pairs to 1-7: : (1, 1) .... (1, 5) --------> 1 : (1, 6) .... (2, 4) --------> 2 : (2, 5) .... (3, 3) --------> 3 : (3, 4) .... (4, 2) --------> 4 : (4, 3) .... (5, 1) --------> 5 : (5, 2) .... (5, 6) --------> 6 : (6, 1) .... (6, 5) --------> 7 : (6, 6) -------------------> do it again
| f**e 发帖数: 1269 | 6 同上前围观美女!
【在 t*****y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : make sense : 谢谢美女!
| l***e 发帖数: 480 | | c******a 发帖数: 198 | 8
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~这个能行?
【在 a**********s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : generate 1-6 twice, then map pairs to 1-7: : (1, 1) .... (1, 5) --------> 1 : (1, 6) .... (2, 4) --------> 2 : (2, 5) .... (3, 3) --------> 3 : (3, 4) .... (4, 2) --------> 4 : (4, 3) .... (5, 1) --------> 5 : (5, 2) .... (5, 6) --------> 6 : (6, 1) .... (6, 5) --------> 7 : (6, 6) -------------------> do it again
| z****e 发帖数: 2024 | 9 your way works and is fine. But we can still improve it.
1. there is a waste (6,6), as you see, you have to do it over again.
2. order dependency. The first time to throw the dice and second time is
different. ie (3,4) and (4,3) map to different numbers.
There is a way to improve and remove the previous 2 drawbacks.
generate 1-6 twice and get a 6*6 table. fold your table along the diagonal
line (upper-left to lower-right).
Now you have 21 elements which is 3*7, and there is no order dependency
a
【在 a**********s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : generate 1-6 twice, then map pairs to 1-7: : (1, 1) .... (1, 5) --------> 1 : (1, 6) .... (2, 4) --------> 2 : (2, 5) .... (3, 3) --------> 3 : (3, 4) .... (4, 2) --------> 4 : (4, 3) .... (5, 1) --------> 5 : (5, 2) .... (5, 6) --------> 6 : (6, 1) .... (6, 5) --------> 7 : (6, 6) -------------------> do it again
| g*******y 发帖数: 1930 | 10 inequal probability. prob(i,j)+prob(j,i) = 2*prob(i,i)
actually in this very problem, you cannot improve, since (6*6) % 7 = 1
if the mod is >=2, then there's a chance to improve.
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : your way works and is fine. But we can still improve it. : 1. there is a waste (6,6), as you see, you have to do it over again. : 2. order dependency. The first time to throw the dice and second time is : different. ie (3,4) and (4,3) map to different numbers. : There is a way to improve and remove the previous 2 drawbacks. : generate 1-6 twice and get a 6*6 table. fold your table along the diagonal : line (upper-left to lower-right). : Now you have 21 elements which is 3*7, and there is no order dependency : a
|
|