Coins!
Coins as statistical machines: basic probability, combinatorics, independence, the binomial formula, and Bayes' theorem — with interactive visualizations.
Coins are our first model of a statistical machine — a simple device that randomly produces one of a finite number of results with some probability. For our purposes, a coin is any object or mechanism that, when flipped, produces one of two outcomes: heads () or tails (). The Romans called this practice navia aut caput (“ship or head”), after the galley and portrait that appeared on either side of their currency — one of the earliest ways humans took chance into their own hands.
The Basics
A coin is characterized by a single parameter :
A fair coin has , meaning heads and tails appear with equal likelihood. We assume the coin must land on one side or the other.
Counting probability. When all outcomes are equally likely, probability is:
⚠️ Common mistake. The formula above only applies when every outcome is equally likely. A classic confusion: “there are two outcomes — winning or losing the lottery — so the probability is .” The error lies in treating distinct outcomes as equally likely ones. If 10,000 lottery tickets exist and any could win with the same probability, the correct denominator is 10,000, not 2.
Question 1. You flip a fair coin 10 times and get tails every time. What is the probability the next flip is heads?
Answer
. Each flip is independent — past results have no influence on future flips.
Question 2. What is the probability of flipping with a fair coin?
Answer
We can list all 8 outcomes for 3 flips:
| Flip 1 | Flip 2 | Flip 3 | ? |
|---|---|---|---|
| H | H | H | ✓ |
| H | H | T | |
| H | T | H | |
| H | T | T | |
| T | H | H | |
| T | H | T | |
| T | T | H | |
| T | T | T |
One desired outcome out of eight total:
Question 3. What is the probability of flipping exactly one head in three flips?
Answer
Three sequences have exactly one head — , , — out of eight total:
| Flip 1 | Flip 2 | Flip 3 | Exactly one ? |
|---|---|---|---|
| H | H | H | |
| H | H | T | |
| H | T | H | |
| H | T | T | ✓ |
| T | H | H | |
| T | H | T | ✓ |
| T | T | H | ✓ |
| T | T | T |
Question 4. What is the probability of flipping exactly 5 heads in 10 flips of a fair coin?
Answer
Ten flips produce too many outcomes to list — there are of them. Let’s split the problem.
Number of desired outcomes
We need to choose which 5 of the 10 positions are heads. We have 10 choices for the first head, 9 for the second, and so on, giving
ordered placements. But this overcounts: labeling the five heads treats them as distinguishable when they are not.

Each of the orderings of those labels maps to the same physical sequence of heads and tails — so we divide by :
This is the choose function, also written and read “10 choose 5.”
Number of total outcomes
Each flip has 2 outcomes, so 10 flips give equally likely sequences.
Combining both:
The choose function is just the entrance to combinatorics — a rich field dedicated to the art of counting. We will use it repeatedly going forward.
Question 5. What is the probability of flipping at least one head in 10 flips?
Answer
Summing over all non-zero head counts is tedious. Instead, use the complement: only one sequence has no heads at all (), so
Question 6. A weighted coin has . What is the probability of flipping ?
Answer
Counting probability does not apply here because and are not equally likely. We need a different strategy.
Notice that each flip is independent: the outcome of one does not affect any other. This means we can multiply:
Implementing a Coin
import random
class Coin:
"""A coin that lands heads with probability p."""
def __init__(self, p=0.5):
self.p = p
def flip(self):
return 'H' if random.random() < self.p else 'T'
Set Notation
Now that we can compute basic probabilities, the next step is combining them. Set theory gives us a precise language.
Define the sample space as the set of all possible outcomes. An event is any subset .
For three coin flips: . The event “exactly one head” is .
Given an event , we write its probability as . Set operations produce new events:
| Operation | Notation | Probabilistic meaning |
|---|---|---|
| Complement | Probability that does not occur | |
| Intersection | Probability that both and occur | |
| Union | Probability that or (or both) occur |
Two facts follow immediately:
- Independence. Events and are independent if and only if .
- Inclusion-Exclusion (PIE).
Question 6 (revisited with set notation). A weighted coin has . What is ?
Answer
Let , , be the events “first flip is ”, “second flip is ”, and “third flip is .” Since flips are independent, , and the same holds for any pair. Applying this twice:
Question 7. Given a coin with , derive the probability of getting exactly heads in flips.
Answer
From Question 4, there are sequences of flips containing exactly heads. By independence, any specific sequence of heads and tails has probability . Since there are such sequences:
Question 8. For , prove:
Answer
Apply the Binomial Theorem: .
Set and :
Simulation
The formula from Question 7 makes a testable prediction: if we flip a weighted coin times and repeat the experiment many times, the proportion of trials with each head count should approach as the number of trials grows. Let’s verify this.
import math
NUM_TRIALS = 10_000
NUM_FLIPS = 8
COIN_WEIGHT = 3/4
GOAL_HEADS = 5
coin = Coin(p=COIN_WEIGHT)
probability_of_goal = (
math.comb(NUM_FLIPS, GOAL_HEADS)
* COIN_WEIGHT ** GOAL_HEADS
* (1 - COIN_WEIGHT) ** (NUM_FLIPS - GOAL_HEADS)
)
num_heads = []
for _ in range(NUM_TRIALS):
flips = [coin.flip() for _ in range(NUM_FLIPS)]
num_heads.append(flips.count('H'))

After 10,000 trials the simulated distribution closely matches the theoretical binomial — for and , the most likely outcome is 6 heads, with as predicted.
The controls below mirror the four parameters in the code. Press Run Simulation to generate your own trials, then try changing the goal, adjusting the coin weight, or cranking up the trial count to see how quickly the empirical distribution converges to theory.
Bayes’ Rule
The final concept we introduce here is conditional probability — the probability of an event given information about another event.
Given events and with , the conditional probability of given is:
From a set-theory perspective, this restricts the sample space from all of down to : we are asking “among the outcomes in , what fraction also belong to ?” We will see a geometric picture of this shortly.
Question 9. Events and are independent, with and . What are and ?
By independence, , so:
When and are independent, conditioning on does not affect the probability of . The converse is also true: if conditioning leaves the probability unchanged, the events are independent.
By the same reasoning:
Note: (intersection is commutative), but conditioning is not — in general.
Question 10. You flip a fair coin 3 times. Given that the first flip is heads, what is the probability that all three flips are heads?
Answer
Left to the reader. Hint: let and “first flip is .” How many outcomes are in ? Does ?
Question 11. You have two coins: a fair coin () and a weighted coin (). You pick one at random and flip it, and it comes up heads. What is the probability that the next flip is also heads?
Answer
Left to the reader. Hint: use the first flip to update the probability you are holding the weighted coin (Bayes’ theorem), then compute the expected probability of heads on the second flip as a weighted average over both coins.
Geometric Interpretations
Visualize Bayes’ theorem as regions of a sample space. The full grid represents . Paint event (blue) and event (orange) and watch the stats panel compute , , and in real time.
Penney’s Game
Coming soon.
Player A selects a sequence of heads and tails (length 3 or longer) and shows it to Player B. Player B then selects a different sequence of the same length. A fair coin is tossed until one player’s sequence appears as a consecutive run. The player whose sequence appears first wins.
Despite appearances, this game is not fair — for any sequence Player A picks, Player B can always choose a sequence that is strictly more likely to appear first. We will analyze specific matchups and derive a general strategy.
Additional Problems
Coming soon.