Image clicked and formatted by Mr. Chandra Sekhar for fermibot.wordpress.com

This post is entirely dedicated to the simulation of roll of fair dice. We will start with one dice and extend it to several of them. I will also provide a python code which you can use to do the simulations yourself.

#### Roll of One Dice

This is pretty simple. We will need a Uniform Random Number from 0 to 1 and then we need to use conditional statements used in conjunction with that do generate a dice. The algorithm is explained as follows.

Generate a Uniform random number u ~ U(0, 1)

- If 0 ≤ u < 1⁄6, return 1
- else if 1⁄6 ≤ u < 2⁄6, return 2
- else if 2⁄6 ≤ u < 3⁄6, return 3
- else if 3⁄6 ≤ u < 4⁄6, return 4
- else if4⁄6 ≤ u < 5⁄6, return 5
- else if 5⁄6 ≤ u < 1, return 6

- else if4⁄6 ≤ u < 5⁄6, return 5

- else if 3⁄6 ≤ u < 4⁄6, return 4

- else if 2⁄6 ≤ u < 3⁄6, return 3

- else if 1⁄6 ≤ u < 2⁄6, return 2

There you have it! This is your digital dice.

Because *u* can have an outcome between 0 and 1 at any given iteration, we would like to see how the outcomes look so in the long run. The histograms below represent that same.

##### Sum of Two Dice

This is the case where we observe sum of outcomes of two different dice. This will give out a different kind of distribution (a triangular distribution). We can see that below.

#### Sum of Three Dice

##### Sum of Four Dice

##### Sum of Five Dice

##### Sum of Six Dice

##### Sum of Seven Dice

### Python Code and Output

##### Code used

The following snippet shows the code that has been used for the simulation

I have also used python 3.5 to create a dice using the same logic. The screenshot is shown below. The input parameters are as follows

- An initial seed value
- the number of iterations

The output is a list of random integers in the range 1 to 6

### Codes for download:

Please drop a comment below if you have downloaded any of these files. Thanks

End of the Post

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.