Dice and Coin Toss Probability

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

 

 

 

 

 

2

3

4

 

 

 

 

3

4

5

6

 

 

 

4

5

6

7

8

 

 

5

6

7

8

9

10

 

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 21 possible outcomes, and 3 of these outcomes are 7s, the chance of a sum of 7 is 3/21 or 1/7.  The chance of a 6 or 8 is also 1/7 and so on down to the chances of a 2 or a 12 which are each 1/21.

 

If 3 dice are thrown, the above table becomes cubical in order to support the 6 new sides.  If the 6 new sides extend along the outward z axis starting (x,y)=0,  then the cube's filling will be just a tetrahedron with legs along the  (x,y,z) axes.

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.

           

           



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