[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
If I roll six dice, what is the probability that they will all show the same number on top?
Background & Techniques
This program originated from a user inquiry about whether he was wasting his money on a dice game at his club. The game is to throw six dice and win $1,000 if all six show the same number. It costs $1 to to play three games (rolling all 6 dice each time). A game is fair, i.e. you break even "in the long run", if the odds of winning, stated as 1 in X tries on average, pays you X dollars for each dollar you spend.
If we imagine throwing one die at a time, the first die can show any value. Thereafter the chance of matching that first number is 1/6 for each remaining die and the probability that all 5 will will show the same number is P =1/6 x 1/6 x 1/6 x 1/6 x 1 /6 = 0.000129. The units for this number are "successes per trial". The reciprocal of P, (1/P), therefore has units "trials per win". In this case, 1/P = 7776 trials per win, i.e. one win on average for every 7776 games played. If we paid $1 per game we should win $7776 each time we won in order to break even. Since in this case it costs 1/3 dollar per game, we should receive 7776/3 or $2592 for each win if we are to break even in the long run. Players should realize that the phrase "in the long run" can reflect a very long run indeed.
The program included here calculates experimental as well as theoretical results. On each click of the Six of a Kind button, it generates 1,000,000 sets of 6 random numbers representing 6 thrown dice and counts the number of times that all 6 results are the same. These results as well as the theoretical results are displayed for each button click. Version 2 also counts the shortest and longest strings of consecutive losses between wins and the maximum drawdown, maximum winning and final winnings after the million games. The "drawdown" represents the capital required to to keep playing while waiting for that next win.
Our "Six of a Kind" case is presented as Case 2 of four cases that are analyzed by the program:
You have enough information to calculate the odds with a calculator before running the program if you choose. I did and got one wrong. Case 4 initially seemed similar to Case 2; the probability of any number is 1/6 so it shouldn't matter if we are looking for 1's, 2's, or 3's, etc. Well, in this case it does. , Luckily, the experimental results made me rethink my theory to get the correct answer.
Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.
The source code includes two versions of the program. Version 1 has about 25 lines of code for each of the four cases with about half of them adding the output lines which display results. We'll call it Beginners level and explain the code this way:
An interesting note on currency formats for the dollar amounts displayed by Version 2.. The negative dollar amounts are displayed by default as accountants commonly do, enclosed in parentheses. The global variable which controls this within Delphi is NegCurrFormat, a byte value, but there is no documentation about how the byte is interpreted. A Web search on Locale_INegCurr will point to a Microsoft page that defines the possible values and their effect on the display. Byte value "1" replaces the parentheses with negative-sign currency-sign value, e.g. ($100) becomes -$100. I set NegCurrFormat to 1 in the FormActivate procedure to implement this change,
Version 2 is the only version included in the executable download but I've include both versions in the source download.
Suggestions for Further Explorations
Copyright © 2000-2017, Gary Darby All rights reserved.