# Distribution Of Dice Sums

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 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 :)

## 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 :

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

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)
```

## Related Questions

- → How to configure JSON for graphql query?
- → Google couldn't fetch my sitemap.xml file
- → A lot of socket endpoints in python?
- → Historical price per minute between two timestamps for a cryptocurrency
- → How to get a value from a list of dictionaries - Python 3.7.1
- → What is the optimal way to parse these strings in Python?
- → Short Order on Binance futures testnet resulting in APIError (ReduceOnly Order is Rejected)
- → values subtracted while iterating through list has random miscalculations
- → Foreign key query error in case of custom uint64 field which was used as a primary key
- → Grouping all tests Python
- → Using #!python2 not working to run under Python 2
- → Storing last 3 scores and deleting older scores and calculating average?
- → Checking if input is in a list of numbers in python