Dice and Coin Toss Probability

Introduction

            Probability of a particular discrete event is determined by dividing the number of ways that event can occur by the number of ways all events of that type can occur.  A good example of an event is the occurrence of having a die land with the side with 5 dots upward.  Since there are 6 sides on a die, the total number of events like this that can occur are 6.  Therefore the probability of getting a 5 is 1/6.  Obviously, the sum of all of the side probabilities is 6/6 or 1.

Dice and Coin tossing

Dice is a pervasive game played in casinos.  It’s also a good subject for the study of probability.  It’s relatively easy to compute the odds when only one or two dice are thrown but it gets more difficult when three or more are thrown.  For the probability of sums of two dice, one can just construct a table like the following:

 

 

1

2

3

4

5

6

1

2

3

4

5

6

7

2

3

4

5

6

7

8

3

4

5

6

7

8

9

4

5

6

7

8

9

10

5

6

7

8

9

10

11

6

7

8

9

10

11

12

 

Here the number of dots on the sides of die number 1 are listed in the left column and the dots on the sides of die number 2 are listed on the top row.  The inner part of the table lists the sums of items in the left column and the top row.  Since there are 36 possible outcomes, and 6 of these outcomes are 7s, the chance of a sum of 7 is 6/36 or 25%.  The chance of a 6 or 8 is 5/36 and so on down to the chance of a 2 or a 12 which are each 1/36.

 

If 3 dice are thrown, the above table becomes cubical because the number of outcomes is multiplied by 6 and hence we have 216 independent possible outcomes. To compute the odds for sums for 3 or more dice, it is preferable to use a computer.

One can use two different approaches:

  1. Use the computer’s random number generator to simulate a huge number of dice throws and get the approximate odds for each possible sum from the frequencies of occurrence of the resulting sums,
  2. Use an algorithm that simulates the above table but in N dimensions, where N is the number of dice being tossed, to get the exact odds of each possible sum.

The latter approach is more complicated to program but it runs much faster for a large number of dice throws.  Both approaches are fairly simple to modify so that not all of the dice in each throw need to have 6 sides. 

 

For example, suppose the new type of dice have only 2 sides such as a coin which has “Heads” and “Tails”.  Since this is a binary example, it is convenient to evaluate the Heads side as 1 and the Tails side as 0.  Then we just need to sum the 1’s that we obtain on each random throw of N coins.  Of course the minimum sum is 0 which means that all N coins have landed Tails and the maximum sum of 1’s is N which means all N coins have landed Heads.  These are the most unlikely cases.  For coins the probabilities are very conveniently given by Pascal’s Triangle[1].  This triangle is the set of coefficients of the terms of a binomial algebraic expression taken to the powers 1..N.  For example when the power is 3, there are 4 coefficients, 1 3 3 1, which, when divided by 8, sequentially correspond to the probabilities of 3 Heads, 2 Heads and 1 Tail, 1 Head and 2 Tails, and 3 Tails.  Reference 1 show that Pascal’s Triangle is quite easy to build from the top down by adding two numbers from the upper adjacent layer to get the value of the number in the present layer.  Therefore, if just a few coins are thrown, a computer is not needed.

If, however, there are a lot of coins or even a few dice, then a computer is much better way.  The algorithm that I used for an arbitrary number of items in each throw is called recursion.  Below I list the algorithm I used:

private void loop(int diceNo, int nDice) {

              if (diceNo >nDice) return;

              for (int side=1; side<=sides; side++) {

              val[diceNo]=side;

              if(diceNo==nDice) {

                     int valSum=0;

                     for(int die=1;die<=nDice;die++)

                     {

                     valSum+=val[die];

                     }

                     sumVals[valSum]++;

              }

              loop(diceNo+1, nDice);

              }

       }

This function called “loop” is recursive in that, at the bottom, it calls itself until diceNo becomes greater than nDice, which is the number of dice in the throw.  The for(int side..) loop steps through the sides of each die.  The array val[] saves the number of dots on the side so that they can be summed in the for(int die…) loop.  Then that sum is used as the index of  the array sumVals[] which will be incremented by 1 for each loop() call.

 

For both dice tossing and coin tossing, I provide triangular arrays of results as well as linear arrays.  For coin tossing, these arrays are the same as Pascal’s Triangle only, for my convenience, it is inverted.   For dice tossing sums, I also provide a plot of the probability per unit sum bin Vs the particular sum.

           

I have also included a third topic in this chapter where I compute the both random and exact probability of obtaining a given number of particular sides on a single dice throw.  On the same topic, I include the frequencies of occurrence of side pairs, triplets, etc. for various numbers of dice tossed. 

           

           



[1] http://en.wikipedia.org/wiki/Pascal's_triangle