---
title: Probability as long-run frequency
heading: What "a one-in-six chance" actually predicts
eyebrow: A11 · Lesson 1 · Probability as long-run frequency
xp: 40
---

::: hook
Noise in an amplifier, bit errors on a link, the time between radioactive decays in a smoke detector: engineers deal constantly with things they can't predict one at a time. They can predict them in bulk. Roll a die once and anything can happen; roll it 60,000 times and you'll get very close to 10,000 sixes. Probability is the number that the fraction settles toward, and learning how fast it settles is what lets an engineer say a link has an error rate of one in a billion.

::: play
- The coin lands heads with probability $p$. The top panel tracks the fraction of heads so far; the dashed line is $p$.
- Look at the first 20 flips, then the last 400. How far does the fraction stray from $p$ early on, and late?
- Press New samples several times. Does the early part look the same each time? The late part?
:::
:::

```sim plot
view: random
x: v = -0.5..1.5
slider: p = 0.05..0.95 step 0.05 = 0.5
sample: coin(p) | mean: F
trials: 2000
bins: 2
trace: 2000 | running
marker: trace = p | label: p
readout: fraction of heads in 2000 = F
```

```sim plot
view: random
x: v = 0.5..6.5
slider: n = 6..60000 = 60 log
sample: dice(1)
trials: n
bins: 6
density: 1/6
measure: step(v - 5.5) | name: P
readout: fraction of sixes = P
readout: count of sixes = P*n
```

::: predict
## You roll a fair die 60 times, then 60,000 times. Which run is more likely to land within 1% of exactly one-sixth sixes?

- [ ] The 60 rolls
- [x] The 60,000 rolls
- [ ] They're equally likely
- [ ] Neither can

::: reveal
The 60,000 rolls. With 60 rolls you'd need almost exactly 10 sixes, and you often get 7 or 13. With 60,000 the fraction is almost always within 1% of 1/6, though the count of sixes itself still wanders by a hundred or so. The fraction settles because its random wobble shrinks as $1/\sqrt{n}$ (lesson 33 explains why); the count's wobble grows as $\sqrt{n}$, but more slowly than $n$.
:::
:::

::: nameit
## Probability

**Long-run frequency.** Repeat an experiment many times under the same conditions. The **probability** of an outcome is the fraction of trials in which it happens, in the limit of many trials. A fair die has six equally likely faces, so each has probability $\tfrac16$. The fraction in any finite run wobbles around that value, and the wobble shrinks as the run gets longer: the **law of large numbers**.

**Rules.** Probabilities are between 0 (never) and 1 (always), and the probabilities of all the possible outcomes add to 1.

- **Not:** $P(\text{not } A) = 1 - P(A)$.
- **Or,** for outcomes that can't happen together: $P(A \text{ or } B) = P(A) + P(B)$. A die shows 5 or 6 with probability $\tfrac26$.
- **And,** for **independent** events (one tells you nothing about the other): $P(A \text{ and } B) = P(A)\,P(B)$. Two dice both show six with probability $\tfrac1{36}$.

**At least one.** The chance that something happens at least once in $n$ independent tries is easiest through "not": 

$$P(\text{at least once}) = 1 - (1 - p)^n$$

If each of 1000 bits is wrong with probability $10^{-4}$, the chance a 1000-bit packet has at least one error is $1 - (1 - 10^{-4})^{1000} \approx 9.5\%$. For small $p$, that's close to $np$ (here 10%) as long as $np$ is small.

**Counting.** When outcomes are equally likely, probability is counting: favorable outcomes over all outcomes. Two dice have 36 equally likely results, and 6 of them sum to 7, so $P(\text{sum} = 7) = \tfrac16$.

**Expected counts.** In $n$ independent trials each with probability $p$, you expect about $np$ successes. That's what the flat line on the dice histogram shows: $n/6$ of each face.
:::

::: example
## A link loses 1 packet in 1000, independently. What is the chance of at least one loss in a 500-packet transfer?

::: solution
1. **Use the complement.** The chance of no losses in 500 packets is
   $$0.999^{500} = 0.606$$
2. **At least one loss.**
   $$1 - 0.606 = 0.394$$
3. **Why adding overcounts.** Adding $500 \times 0.001 = 0.5$ would overcount, because it counts transfers with two or more losses several times.

**Answer:** the chance of at least one loss is 0.394.
:::
:::

::: example
## Two dice are thrown 600 times. About how many sevens do you expect, and how many doubles?

::: solution
1. **Count the sevens.** Six of the 36 equally likely outcomes sum to 7: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1). So
   $$P = \frac{1}{6}$$
2. **Expected sevens.** In 600 throws you expect about
   $$600 \times \frac{1}{6} = 100$$
3. **Doubles.** Doubles are also 6 outcomes of 36, so you expect about 100 of them too.

**Answer:** about 100 sevens and about 100 doubles.
:::
:::

::: example
## In a group of 23 people, what is the chance that two share a birthday?

::: solution
1. **Use the complement.** It's easier to find the chance that all 23 birthdays differ:
   $$\begin{aligned} P &= \frac{365}{365} \times \frac{364}{365} \times \cdots \times \frac{343}{365} \\ &= 0.493 \end{aligned}$$
2. **At least one shared birthday.**
   $$1 - 0.493 = 0.507$$
   better than even.
3. **Tags and hashes.** The same arithmetic tells you how often random 16-bit tags collide: with $2^{16}$ possible values, a few hundred tags already make a collision likely. Hash and ID designers size their fields with this "birthday bound".

**Answer:** the chance that two of the 23 share a birthday is 0.507, better than even.
:::
:::

::: check
given: n = 2..5 int
answer: (1/6)^n
tolerance: 0.5%

## You roll {n} fair dice. What is the probability that every one shows a six?

::: right
Right. The dice are independent, so multiply: $(1/6)^{\given{n}}$ = {answer}.
:::

::: misses
- [n/6] Adding is for outcomes that exclude each other. For "all of these at once," multiply.
- [1/(6*n)] Multiply the probabilities: $(1/6)^n$.
- [any] Not yet. For independent events, $P(\text{and})$ is the product.
:::
:::

::: check
given: p = 1e-4 | 1e-5; n = 10000 | 100000 | 1000000
answer: 1 - (1 - p)^n
tolerance: 0.5%

## Each bit of a block is wrong with probability {p}, independently. What is the chance that a {n}-bit block has at least one error?

::: right
Right. $1 - (1 - p)^n$ = {answer}.
:::

::: misses
- [n*p] That's the small-probability estimate. It overcounts packets with several errors; use $1 - (1 - p)^n$.
- [(1 - p)^n] That's the chance of no errors at all.
- [p^n] That's the chance that every bit is wrong.
- [any] Not yet. Find the chance of no errors, then subtract from 1.
:::
:::

::: check
kind: parts
given: s = 2 | 3 | 4 | 5 | 6

## Two fair dice are rolled.

::: part
answer: (s - 1)/36
tolerance: 0.5%

### What is the probability that they sum to {s}?

::: misses
- [1/11] The 11 possible sums aren't equally likely. Count the pairs.
- [s/36] Count the pairs that sum to {s}: there are {s} − 1 of them.
- [any] Count the ordered pairs (first die, second die) that give {s}, out of 36.
:::
:::

::: part
answer: 1 - (s - 1)/36
tolerance: 0.5%

### And that they don't sum to {s}?

::: misses
- [(s - 1)/36] That's the chance they do.
- [any] $P(\text{not } A) = 1 - P(A)$.
:::
:::

::: right
Right. Counting equally likely outcomes, then using "not."
:::
:::

::: check
given: n = 600 | 6000 | 60000; f = 2 | 4
answer: n*f/6
tolerance: 0.5%

## A fair die is rolled {n} times. About how many times do you expect a {f} or lower?

::: right
Right. $P(\text{roll} \le \given{f}) = \given{f}/6$, and you expect $n$ times that: {answer}.
:::

::: misses
- [n/6] That's for one particular face. Count every face from 1 to {f}.
- [n*(6 - f)/6] That's the count above {f}.
- [any] Not yet. Expected count $= np$.
:::
:::

::: check
kind: choice

## A coin has landed heads 8 times in a row. What is the chance the next flip is heads?

- [x] One half
- [ ] Less than one half: tails is due
- [ ] More than one half: it's on a streak
- [ ] Almost zero: 9 in a row is very rare

::: right
Right. Independent flips have no memory. A streak of 9 is rare, but given the first 8, the 9th is still 50–50.
:::

::: misses
- [2] The coin doesn't remember. The law of large numbers works by dilution, not by correcting.
- [3] A fair coin has no streaks: each flip is independent.
- [4] That's the chance of 9 heads before any flips. Once 8 have happened, only the last one is uncertain.
:::
:::

::: check
kind: parts
given: p = 0.001 | 0.01; n = 100 | 500

## Each of {n} packets is lost independently with probability {p}.

::: part
answer: 1 - (1 - p)^n
tolerance: 0.5%

### What is the chance of at least one loss?

::: misses
- [n*p] That adds overlapping cases; use the complement.
- [any] $1 - (1 - p)^n$.
:::
:::

::: part
answer: n*p
tolerance: 0.5%

### What is the expected number of losses?

::: misses
- [any] $np$.
:::
:::
:::

::: check
kind: derivation
vars: p = 0.001..0.1, n = 2..50

## A system works only if all $n$ independent parts work, each failing with probability $p$.

::: step
answer: (1 - p)^n

### What is the chance it works?
:::

::: step
answer: 1 - (1 - p)^n

### What is the chance it fails?
:::

::: right
Right. For small $p$ the failure chance is close to $np$, but the complement is exact.
:::
:::

::: explain
## A test finds 3 errors in 100 bits. Why shouldn't you conclude the error probability is 3%?

::: model
In a short run, the fraction of errors wobbles a lot around the true probability: with only 100 bits, 3 errors could easily come from a true rate of 1% or 6%. Probability is the fraction in the long run, and the wobble shrinks only as the square root of the number of trials. To measure a rate reliably you need enough trials to see many errors, which is why bit error rate tests run for billions of bits.
:::
:::

::: practice

::: check
given: p = 0.1 | 0.2 | 0.3; q = 0.4 | 0.5
answer: p*q
tolerance: 0.5%

## Two independent parts fail with probabilities {p} and {q}. What is the chance both fail?

::: misses
- [p + q] For "both," multiply.
- [any] $P(A \text{ and } B) = P(A)P(B)$.
:::
:::

::: check
given: p = 0.01 | 0.02 | 0.05; n = 10 | 20 | 50
answer: 1 - (1 - p)^n
tolerance: 0.5%

## A part has a {p} chance of failing each year. What is the chance it fails at least once in {n} years?

::: misses
- [n*p] That overcounts; use $1 - (1 - p)^n$.
- [any] One minus the chance of surviving every year.
:::
:::

::: check
given: k = 2..4 int
answer: k/6
tolerance: 0.5%

## A fair die is rolled. What is the chance of one of {k} particular faces?

::: misses
- [1/6] Add the chances of each face: they can't happen together.
- [any] $k/6$.
:::
:::
:::
