Brute Force Probability a la Flash
Question: If a coin is flipped 100 times, what is the likelihood of 7 heads coming up in a row?
This question perplexed my friend Andy and me at the gym the other day for about an hour. We couldn’t agree on the math needed to calculate the result, so I decided to whip up a quick “brute force” experiment in Flash. In this project (embedded below) a simulated coin is rapidly flipped 100 times, and runs of 7 heads are recorded as they happen. After a few thousand runs the results appear to approach the predicted result of about a 31.8% chance (plus or minus a few points – see the full explanation here).
Of course, the coin flipping in this experiment isn’t truly random. I’m using Flash’s built in Math.random() function, which utilizes your system’s clock to create pseudo-random numbers. But all in all things appear to work out.
Yay math.
October 9th, 2009 at 11:04 pm
Nice presentation of a Monte Carlo simulation. The reason, I suspect, that you’re getting values above my 31.8% calculation is that you’re answering a different question than I was. I wanted to know the percentage of 100-flip sequences that would have at least one run of seven or more heads. You seem to be dividing the number of 7-head runs by the number of 100-flip sequences. This should give you a number a bit higher than mine because some sequences will have more than one 7-head run.