When you roll two six sided dice, the total is a number from 2 to 12, with a greater probability toward the middle of that range. The distribution of results is shown in the graph generated by the program below.
The dice rolls have 36 possible results ("1 and 6" is considered to be different from "6 and 1"), of which six have a total of 7. So the "probability" of rolling a 7 is 6/36, or 1/6. Probability is usually expressed as a fraction, with 1 (100%) meaning that an event must happen. There is a probability of 1 that the total of 2 six-sided dice will not be 20.
Nature doesn't always follow probability. In the graph below, I performed 1000 dice rolls and plotted the results. As you can see, the shape is similar, but 8 came up as the most frequent total. (Running a larger simulation would be more likely to give a truer picture, but that is not always feasible.)
How many dice rolls should it take until you roll a 7? You might think that since 7 has a 1/6 probability, that you get a cluster around 6 with the numbers falling off on either side, but the graph shape is quite different. Unlike the first two graphs, the upper limit is not fixed. It's not likely, but you could roll 20 times without getting a seven. And the most probable result is one roll, with the probabilty decreasing with each successive roll. Why? Well, each roll has a 1/6 chance of being the last one. That means that each roll removes 1/6 of the remaining distribution, and that 5/6 is accounted for by the numbers "to the right". The "Expected Value" is the average of (1 * (occurrences in 1 roll) + 2 * (occurrences in 2 rolls) + ... n * (occurrences in n rolls)) / occurrences.
If you run this code, you'll find that the Expected Value does come out very close to 6. In a future article, I'll show you how to get the exact number rather than a simulation. Several Project Euler problems require this calculation.
For more information on the Chart control, see some of my earlier posts (for example, this one ).
Posted Apr 10 2011, 09:12 AM by LarryBlake Filed under: Dictionary, VB, Chart control, Expected Value, Project Euler, Probability

0 comments:
Post a Comment