Skip to content
Quaestio

Coin flip

One press, heads or tails, exactly half each.

Press Flip.

Embed

Embed this tool on your site

Copy the code and paste it where the tool should appear, such as a blog post or a school page. It is free, the box has no ads and the tool calculates in the visitor’s browser.

How it works

The coin is flipped with the browser’s cryptographic randomness, so heads and tails are exactly as likely. A real coin is not quite: experiments show it lands slightly more often on the side that started face up.

Every flip is independent of the ones before. After five heads in a row the chance of heads on the next flip is still exactly one half. Believing otherwise is known as the gambler’s fallacy.

The tally below shows the split for the session. Over many flips it approaches half each, but in short runs long streaks of the same side are more common than people expect.

How each flip is decided

The tool asks the browser for a random whole number between 0 and 4,294,967,295 through the getRandomValues function of the Web Crypto API. The W3C specification says the values should come from a well-established cryptographic pseudo-random number generator seeded with high-quality entropy. The number is divided by two: an even number gives heads, an odd one tails.

Because two divides the 4,294,967,296 possible values exactly, no value ever has to be thrown away, as it must be for a six-sided die. The tally below the result lives only in the page’s memory, so reloading the page starts it again from zero.

Example: how uneven can it get

A coin is a die with two faces, so the spread can be worked out with the same function the dice roller uses. In 100 flips, exactly 50 heads is the single most likely result, yet it happens in only 7.96% of sessions. The number of heads lands between 45 and 55 in 72.87% of sessions, and between 40 and 60 in 96.48%.

The standard deviation of the number of heads is the square root of 100 × 0.5 × 0.5, which is 5. A tally of 58 heads and 42 tails after 100 flips is within two standard deviations and says nothing about the randomness. In ten flips, all ten land the same way in 0.20% of sessions, about once in 512.

Real coins

A research team led by František Bartoš flipped real coins 350,757 times and found that a coin landed on the same side it started on in 50.8% of flips, with a 95% credible interval of 50.6% to 50.9%. That confirms a physical model by Diaconis, Holmes and Montgomery from 2007, which predicted about 51%. With the starting side chosen at random, heads and tails came up equally often, 50.0%. The tool has no starting side, so that bias does not exist here.

Sources

How the tools are checked