I want to calculate the probability of the event that the sum of all eyes of n dice with s sides (numbered from 1 to s) is equal to t. My language is Python 3.
My current approach is pretty much a try-and-count solution and only works for small numbers (running probability(10, 10, 50) already ate all my RAM and forced me to hard reset):
import itertools
def probability(n, s, t):
all_rolls=list(itertools.product(range(1,s+1), repeat=n))
target_rolls=[l for l in all_rolls if sum(l)==t]
return round(len(target_rolls)/len(all_rolls), 4)
But I honestly don't know how else to solve this. Can you please help me to get on the right track?