Coin Flipping Probabilities

Prelude

It’s been a while since I’ve written anything on my website, and I decided to instead do something a bit different. This post is inspired by real life events!

It was December 31st 2018, we had friends over, and we were naturally playing board games. This time we were playing Secret Hitler. In that game, one person is randomly chosen to be “Hitler”. One of our friend’s ended up being Hitler and afterwards made a comment along the lines of, “I’m always Hitler”! We went to play another round and he stated something like, “Watch me be Hitler again”. This sparked the age-old question of “What is the probability that you’ll get that card given that you’ve already drawn that card”.

In the above scenario, there were nine of us and only one Hitler card. Clearly, the probability of drawing that card are one-in-nine or roughly 11%. The group immediately divided into two camps, namely “the probability of him drawing the card again is one-in-nine” and “the probability of him drawing the card again is much less than one-in-nine”. So which group is correct?! Before I give the answer, I’ll first state that I have argued both sides. I decided that it would be fun to make a simple experiment to demonstrate what the correct answer is.

The Problem

I decided to simplify the problem, slightly, just so that the math is simpler and because it addresses a more commonly asked question – that of flipping a fair coin. A fair coin is one that is equally likely to be one side or the other. In our case, we have a basic coin, having heads on one side and tails on the other. The coin is fair, so the probability of getting heads is 50% and the probability of getting tails is also 50%. I usually call heads, so for the point of this experiment, we’ll say that getting a head is a success.

I already stated the probability of getting heads is 50% – the coin has a heads side and a tails side, and they are both equally likely – but what is the probability of getting heads twice in a row? In this case, it 0.5 * 0.5 = 0.25 or 25%. The first time I flip the coin, there is a 50% probability of getting heads. The next time I flip the coin, there is still a 50% probability of getting heads (the coin hasn’t changed, so neither has the probability). Since I only have a 50% probability of getting a heads the first time and I also only have a 50% probability of getting a heads the second time, this means that half of my flips that were heads the first time, should be heads the second time. Half of 50% is 25%. We can simplify this and state that the probability of me getting heads n flips in-a-row is simply 0.5n.

The Experiment

To demonstrate the above, I decided that we need to test this. While I’ve hinted at what the answer to the question is, I likely still haven’t given someone enough information to know if they should put their money on heads or tails. To test this, I wrote a very simple program (code is here). I like data and the more the better. I figured that the best way to show this would be to simulate one billion coin flips. Why? Well, why not?! One billion is a pretty big number and should be sufficiently large enough to get some valid results. To help put this to scale – one billion words would fill over 10,000 adult novels, which is enough for a small library!

The program is pretty simple – it generates a random number between 0 and 1 (inclusive and exclusive, respectively) and if it’s greater than or equal to 0.5, it’s heads; otherwise, it’s tails. The program then performs the desired number of coin flips, keeping track of how many successes occurred in a row. Since a billion is a big number, I decided to do the trials in parallel, utilizing all 4 hyper-threads on my original Microsoft Surface Pro.

On my relatively “old” computer (six years old, at the time of this writing), the simulation only took 364 seconds to run (roughly 6 minutes). For those of you curious, I encourage you to download the code and run it for yourself! You only need to have Python 3.4+ installed.

Some of you may think that doing the flips in parallel is cheating, because I am then limiting the longest running chain to be one billion / four = 250 million. If we were to see 250 million heads in a row, which has a probability of 0.5250000000 ~= 0, I would gladly re-run the experiment (and make sure that my code doesn’t have any bugs!).

The Results

If you’d like to look at the raw data, feel free to download this CSV.

The max observed successive head flips was 29. This is quite a large number. The theoretical probability of that occurring is 0.529 = 1.86E-9 or roughly one in every 1.8 billion attempts. Given that the coin was flipped a billion times, that’s not out of the question. In such a case, it comes to chance.

If you look at the following graph, you can see that after about eight heads in a row, very few subsequent heads occur.

To see the data a bit more clearly, here is the same thing plotted on a logarithmic scale. From that plot we see that we observed 14 heads in a row just over 30,000 times (actual value of 30,481). This equates to 30481 / 1000000000 = 3.0 * 10-5, which is pretty close to theoretical probability of 0.514 = 6.1 * 10-5 .

But the real question is, if I get 14 heads in a row, am I more likely to see the next flip be tails than heads? If you look at the computed probabilities plot (shown below), you’ll see that the answer is no. The probability is still only 50%.

If you’re wondering what’s happening after about 20 coin flips, the chaotic probabilities are a result of the lack of data points. This is shown in the below plot, where after about 14 successive coin flips, the number of data points significantly drops. In other words, there are so few data points that the results are statistically unsound. You can see that at 14 and fewer successive flips, the probability of getting heads is nearly exactly 50%.

So why? It’s because the coin flips are independent. The coin showing heads before has no bearing on the probability of it being heads again. The common misconception is that because the last n flips were heads, the next flip should be tails. Instead, what is correct is that the probability of observing n + 1 heads is less than the probability of observing n heads. But just because n heads were flipped in succession, it does not mean that the next flip (flip n + 1) is more likely to be tails. As shown above, at flip number n + 1 there is a 50% probability of observing heads, therefore the probability of observing tails remains at 50%.

Conclusion

The probability of a fair coin being flipped and landing on heads is 50%, regardless of how many times the coin previously showed heads. The probability of many successive heads occurring in sequence is very low, but despite that, even if you had a bunch of successive heads, there’s still only a 50-50 chance of the next coin flip being heads.

So if you are at a point where you need to make a bet, and you already saw a bunch of heads get flipped – just remember, you still only have a 50-50 chance of making your money. But if the payout has increased, because others feel that tails is more likely, then put your money on heads – your chances are just as good as the people with their money on tails, but your payout will be much better!

Hopefully this short post helped clear up this age-old question. Feel free to reference this post the next time your friends start debating about who will draw which card next!

If you have additional questions, feel free to drop them in the comments 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: