Here's a short Python program I wrote a long time ago for generating probability tables:
https://gist.github.com/dave-britten/c4b...65ce54497b
Roughly half of it is just processing the user input! Enter one die at a time, and enter a blank line to terminate input.
EDIT: It's so old, in fact, that I just realized it's for Python 2! Here's a quick update to Python 3:
Code:
import re
dice = [] #Input dice as polynomial coefficients
print("Enter face values as non-negative integers, separated by spaces, commas, or semicolons. (e.g. \"1,2;3 4 5 6\")")
while True:
rawdie = [] #List of face values
qty = 1 #Quantity of a single die spec
inp = input("Die " + str(len(dice) + 1) + "? ")
if inp == "":
break
#rawdie = [int(face) for face in inp.split(" ")]
rawdie = [int(face.strip()) for face in re.split(" |,|;", inp) if face.strip()]
qty = input("Quantity? [1] ")
if qty == "":
qty = 1
else:
qty = int(qty)
die = [0] * (max(rawdie) + 1)
for i in rawdie:
die[i] += 1
dice += [die for i in range(qty)]
print(str(rawdie) + " x " + str(qty))
lastresult = dice[0]
for current in dice[1:]:
result = [0] * (len(lastresult) + len(current) - 1)
for x, v1 in enumerate(lastresult):
if v1 == 0:
continue
for y, v2 in enumerate(current):
result[x + y] += v1 * v2
lastresult = result
skipzero = True
p = 0.0
fcum = 0.0
for i in lastresult:
p += i
print("Permutations: {:.0f}".format(p))
print("{:<6} {:<12} {:>10} {:>10} {:>10}".format("Total","Freq","Prob", "p>=", "p<="))
for i, f in enumerate(lastresult):
fcum += f
if f == 0 and skipzero:
continue
skipzero = False
print("{:<6} {:<12} {:>10.3%} {:>10.3%} {:>10.3%}".format(i, f, f / p, (p - fcum + f) / p, fcum / p))