Skip to content

Instantly share code, notes, and snippets.

@tleysh
Last active December 28, 2020 20:36
Show Gist options
  • Save tleysh/98e435f534d9e79b495dcc83f5e24be6 to your computer and use it in GitHub Desktop.
Save tleysh/98e435f534d9e79b495dcc83f5e24be6 to your computer and use it in GitHub Desktop.
#The first binomial
def firstBinomialCoff(num_of_dice,k):
return (math.factorial(num_of_dice)/(math.factorial((num_of_dice-k))*math.factorial(k)))
#The second binomial
def SecondBinomialCoff(num_of_dice,k,s,Total):
return (math.factorial((Total-s*k-1))/(math.factorial((Total-s*k-num_of_dice))*math.factorial((num_of_dice-1))))
#The full expression of Prob
def ProbofEachNum(num_of_dice,s,Total):
Probof6thsidedDiceto_n = (1/s)**num_of_dice
Total_prob = 0
for k in range(0,int((Total-num_of_dice)/s)+1):
Total_prob = Total_prob + ((-1)**k)*firstBinomialCoff(num_of_dice,k)*SecondBinomialCoff(num_of_dice,k,s,Total)*Probof6thsidedDiceto_n
return Total_prob
#The theoretical distribution, Prob for each possible value
def Full_Theoretical_Distribution(num_of_dice,s):
The_range = range(num_of_dice,num_of_dice*s)
The_distribution = np.zeros(len(The_range)+1)
count = 0
for each_possible_number in range(num_of_dice,(num_of_dice*s)+1):
The_distribution[count] = ProbofEachNum(num_of_dice,s,each_possible_number)
count += 1
return list(The_range),list(The_distribution)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment