※ 引述《grapherd (NULL)》之銘言:
: ※ 引述《p2p8ppp (給我錢)》之銘言:
: : https://imgur.com/7cLC5iT
: : 初學者來ㄌ
: : 我模擬1000次就跑好久
: : 是因為我用13顆骰子慢慢骰嗎?
: : 接下來要弄次數分配怎麼寫啊= =
: from collections import defaultdict
: dd = defaultdict(int)
: # 每次 result 直接放入 dd
: dd[result] += 1
: print(dd) # 次數分配結果
: 然後,已經 2017 年了,快改用 python 3 好嗎,別再用 2 了。
: : 不奢望畫圖了= =
: pyplot 或是 matplotlib 都能夠做到,加油,好嗎?
Python 模擬一萬次出來也是一樣歐
https://i.imgur.com/2HjGhzA.png
不過這個有掉到280次以下的
# python3
import numpy as np
import seaborn as sns
def roll_die():
points_total = 0
cutoff = 0
while points_total < 13000:
points_total += np.sum(np.random.randint(1, 7, 13))
cutoff += 1
return cutoff
results = np.array([roll_die() for i in range(10000)])
sns.distplot(results, kde=False)