How it works
Each flip draws one value from crypto.getRandomValues and maps it to
heads or tails with equal probability. Flipping several coins at once
draws each one independently, exactly like tossing a handful of real
coins.
Why not Math.random?
For a casual coin flip either source would work, but crypto.getRandomValues
is the same cryptographically secure generator used elsewhere on this site
for passwords and tokens, so there is no reason to reach for a weaker one
here.
Settling ties fairly
A single flip is the classic way to make an arbitrary choice between two options without bias. Flipping a large batch instead shows how the split between heads and tails narrows toward 50/50 as the number of flips grows.