100万回トライして
平均 : 357
標準偏差 : 23
最大 : 501
最小 : 268
非バーサーク時(期待値 147)の2.4倍。
分布でなんか変なヒゲが生えているのは何なのだろう...?
...仕事します。
import random import numpy import matplotlib.pyplot as plt def normal_dice(dice_num) : vals = [] total_val = 0 random.seed() for num in range(0,dice_num): vals.append(random.randint(1, 6)) #print vals total_val = sum(vals) return total_val def berserk_dice(dice_num) : vals = [] total_val = 0 random.seed() for num in range(0,dice_num): vals.append(random.randint(1, 6)) #print vals total_val = total_val + sum(vals) for num in range(1,6): num_of_same = vals.count(num) if num_of_same > 1 : #print "Bersrk by %d dices of %d marks" % (num_of_same,num) total_val=total_val+berserk_dice(num_of_same) return total_val def hyper_berserk_dice(dice_num) : vals = [] total_val = 0 random.seed() for num in range(0,dice_num): vals.append(random.randint(1, 6)) #print vals total_val = total_val + sum(vals) for num in range(1,6): num_of_same = vals.count(num) if num_of_same > 1 : # print "Bersrk by %d dices of %d marks" % (num_of_same,num) total_val=total_val+hyper_berserk_dice(num_of_same+1) return total_val def main(): dice_num = input("Input dice_num :") trial = input("Input Num. of Trials :") vals=[] for num in range(0, trial) : vals.append(berserk_dice(dice_num)) if num%10000==0: print num vals=numpy.array(vals) print "Mean : ", numpy.mean(vals) print "SD : ", numpy.std(vals) print "Max : ", vals.max() print "Min : ", vals.min() plt.rc('font', **{'family': 'serif'}) fig = plt.figure() ax = fig.add_subplot(111) ax.hist(vals, bins=100) ax.set_title('Berserk with %d dices! (%d trials)' % (dice_num, trial)) ax.set_xlabel('Hits!') ax.set_ylabel('Frequency') plt.show() return None main()