#!/usr/bin/env python
from random import randint
NROLLS=1000000
def rolldice(total, ndice):
for i in range(NROLLS):
dice = []
for d in range(ndice):
dice.append( randint(0, 9) )
dice.sort()
roll = {}
for d in range(ndice):
r = dice[d]
roll[r] = roll.get(r, r) + 10
rollsum = 0
for key in roll.keys():
value = roll[key]
if value > rollsum:
rollsum = value
total[rollsum] = total.get(rollsum, 0) + 1
def header():
print """
Weapons of the Gods Dice Stats
"""
def main():
header()
for ndice in range(1, 11):
total = {}
rolldice(total, ndice)
rolls = total.keys()
rolls.sort()
average = 0
for roll in rolls:
freq = total[roll]
average += roll * freq
average = float(average) / NROLLS
if ndice == 1: diceword = "DIE"
else: diceword = "DICE"
print "| %d %s, average=%4.1f |
" % (ndice, diceword, average)
print "| roll | \t% | \t |
"
for roll in rolls:
freq = total[roll]
chance = 100.0 * float(freq) / NROLLS
if chance <= 0.1: continue
print """| %d |
%7.4f |
 |
""" % (roll, chance, int(chance * 25))
print
print "
"
print ""
if __name__ == '__main__':
main()