Ad

Distribution Of Dice Sums

- 1 answer

I want to study the distributions of sums of dice, especially what happens when the number of dice increases

And for that I know that I have to create a function using a list of numbers and an integer n as arguments and allowing to produce another list of numbers corresponding to the sum of n numbers, a list of enter image description here if the input list of numbers is {xi} and they asked to use a while loop to iterate through the list of numbers.

If anyone has any ideas that would be greatly appreciated :)

Ad

Answer

Well this is a fun experiment, If i understand your question correctly you are looking for distribution of dice sums with variation in dice counts.

Below is the code to get you started

import random
def simulatediceplay(num_of_dice):
  sum = 0
  for i in range(num_of_dice):
    sum +=random.randint(1,6)
  return sum

def generateplay(num_of_dice,num_of_runs):
  lst = []
  for i in range(num_of_runs):
    lst.append(simulatediceplay(num_of_dice))
  return lst

lst = generateplay(4,1000)
import seaborn as sns
sns.distplot(lst);

Output (for simulation of 1000 dice throws of 4 dices :

4 dice throw

Output (for simulation of 1000 dice throws of 8 dices : enter image description here

Below code can help you generate how the stddev and mean changes for the different dice counts

import statistics
listdice =[]
listdev = []
listmean = []
for i in range(1,20):
  lst = generateplay(i,1000)
  listdice.append(i)
  listdev.append(statistics.stdev(lst))
  listmean.append(statistics.mean(lst))

# draw lineplot
sns.lineplot(x=listdice, y=listmean)
# draw lineplot
sns.lineplot(x=listdice, y=listdev)

enter image description hereenter image description here

Ad
source: stackoverflow.com
Ad