【发布时间】:2019-02-03 23:18:47
【问题描述】:
我正在尝试模拟 Chevalier de Mere 的骰子赌注 1000 次,以估计赢得每个赌注的概率。我模拟的事件 掷骰子 4 次时出现 6,我得到的结果与我预期的相似(~0.5)。但是,当模拟掷两个骰子 24 次时出现 6 的事件时,我得到的结果比预期的要高。当我期待〜0.49时,我得到〜0.6。
我运行模拟的方式有问题,还是有其他解释?见代码:
total = 0
for i in range(1000):
if 6 in randint(1,7,(4)):
total +=1
print("The probability a 6 turns up when rolling 1 die 4 times is:",total/1000)
total = 0
for i in range(1000):
for j in range(24):
if 6 == randint(1,7) and 6 == randint(1,7):
total +=1
print("The probability a 6 turns up when rolling 2 die 24 times is:",total/1000)
请帮忙!谢谢!
【问题讨论】:
-
无法复制。给我大约 0.49。
-
在第一种情况下,您似乎拥有自己的
randint实现。它不需要3个参数。在第二种情况下,请说明在掷两个骰子 24 次时是要双 6 还是 any 6,因为 any 6 的概率是 99.984%。我假设您的意思是掷两个骰子 24 倍并获得双 6,即 49.14%。
标签: python simulation probability