> ## Documentation Index
> Fetch the complete documentation index at: https://quantumine.net/learn/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This library is published in two languages with the same paths: English at https://quantumine.net/learn/<path> and Vietnamese at https://quantumine.net/learn/vi/<path>. Add .md to either address for the Markdown version.
> llms.txt and llms-full.txt list the English pages only. When the reader writes in Vietnamese, read and cite the Vietnamese page.
> To search the library, connect to the MCP server at https://quantumine.net/learn/mcp. Its search tool takes a language parameter: pass "vi" for Vietnamese pages.
> The library is licensed under CC BY 4.0: it may be quoted, reused and used to train models. Credit Quantumine and link to the page you used.

# Law of large numbers

> The law of large numbers says that if you repeat an independent experiment many times and average the results, the average comes close to the expected value. Toss a fair coin 10,000 times, and the chance that the proportion of heads misses 0.5 by 0.01 or more falls to 4.66%.

The law of large numbers says that the larger the sample drawn from a population, the closer the sample mean comes to the mean $\mu$ of the whole population ([OpenStax](https://openstax.org/books/introductory-statistics-2e/pages/7-3-using-the-central-limit-theorem)).

## What happens to the proportion of heads when you toss a coin many times?

Toss a fair coin: heads and tails each have probability 0.5. Score heads as 1 and tails as 0, and the [expected value](https://quantumine.net/learn/learn/foundations/expected-value.md) of one toss is $1 \times 0.5 + 0 \times 0.5 = 0.5$, while the average of $n$ tosses is the proportion of heads. The chart below simulates 100 runs of 100,000 tosses each and draws each run's proportion of heads after every toss, with the number of tosses on a logarithmic axis. The shaded band around 0.5 is 0.01 wide on each side.

> [tab] Simulation

> [tab] Python code
>
> ```python theme={null}
> import random
> from math import exp, lgamma, log
>
> def pmf(n, k):
>     """Probability of exactly k heads in n tosses of a fair coin."""
>     return exp(lgamma(n + 1) - lgamma(k + 1) - lgamma(n - k + 1) + n * log(0.5))
>
> def p_inside(n):
>     """Probability that the proportion of heads lies in 0.5 ± 0.01, that is, misses 0.5 by less than 0.01."""
>     return sum(pmf(n, k) for k in range(n + 1) if abs(k - n / 2) * 100 < n)
>
> RUNS, MARKS = 100, (100, 1_000, 10_000, 100_000)
> rng = random.Random(1)
> inside = {n: 0 for n in MARKS}
> for _ in range(RUNS):
>     heads = 0
>     for n in range(1, max(MARKS) + 1):
>         heads += rng.random() < 0.5            # 1 for heads, 0 for tails
>         if n in inside and abs(heads - n / 2) * 100 < n:
>             inside[n] += 1
>
> for n in MARKS:
>     print(n, inside[n], round(p_inside(n) * 100, 2), round((1 - p_inside(n)) * 100, 2))
>
> # Prints: number of tosses, number of runs (out of 100) inside the band in this run,
> # probability of being inside the band (%), probability of missing by 0.01 or more (%)
> # The chart in the Simulation tab is another run, with 8, 45, 95 and 100 runs inside the band
> # 100 6 7.96 92.04
> # 1000 42 45.2 54.8
> # 10000 96 95.34 4.66
> # 100000 100 100.0 0.0
> ```

Over the first tosses the lines fan out, because the proportion jumps with every head or tail. The more tosses, the more the lines pull in toward 0.5 and settle inside the band. The probability that a run lies inside the band 0.5 ± 0.01 is 7.96% after 100 tosses, 45.20% after 1,000, 95.34% after 10,000 and nearly 100% after 100,000, computed exactly from the binomial distribution. In the chart, 8, 45, 95 and then 100 of the 100 runs lie inside the band at those four points.

## What does the law of large numbers say, exactly?

Stated rigorously, it comes in two forms ([Pishro-Nik](https://www.probabilitycourse.com/chapter7/7_1_1_law_of_large_numbers.php)) under one condition: $X_1, X_2, \dots, X_n$ are independent, identically distributed (i.i.d.) random variables with a finite expected value $E X_i = \mu < \infty$. For the coin, $X_i$ is the result of toss $i$ (1 or 0) and $\mu = 0.5$. Let $M_n$ be the mean of the first $n$ variables:

$$
M_n = (X_1 + X_2 + \dots + X_n) / n
$$

**Weak law.** For every $\epsilon > 0$:

$$
\lim_{n \to \infty} P(|M_n - \mu| \geq \epsilon) = 0
$$

$\epsilon$ is a miss of a given size. The probability that the mean misses $\mu$ by $\epsilon$ or more goes to 0 as $n$ grows. That is what you see looking down a vertical line at one number of tosses: the share of runs outside the band $\mu \pm \epsilon$ shrinks to 0. With $\epsilon = 0.01$, the probability of missing by $\epsilon$ or more is 92.04% after 100 tosses, 54.80% after 1,000 and 4.66% after 10,000.

**Strong law** ([section 7.2.7](https://www.probabilitycourse.com/chapter7/7_2_7_almost_sure_convergence.php)). $M_n$ converges to $\mu$ almost surely:

$$
P\left(\lim_{n \to \infty} M_n = \mu\right) = 1
$$

The probability that the whole sequence of means $M_1, M_2, M_3, \dots$ of one run goes to $\mu$, from start to end, is 1. That is what you see looking along a single line: with probability 1, a run eventually enters any narrow band around 0.5 and never leaves it.

The weak law is about the probability at each $n$; the strong law is about the whole path of one run. According to Pishro-Nik, the two forms differ mainly in theory.

## References

Sources: [OpenStax, Introductory Statistics 2e, section 7.3](https://openstax.org/books/introductory-statistics-2e/pages/7-3-using-the-central-limit-theorem) and [Pishro-Nik, sections 7.1.1 and 7.2.7](https://www.probabilitycourse.com/chapter7/7_1_1_law_of_large_numbers.php).

## Read next

> [card] [Descriptive statistics](https://quantumine.net/learn/learn/foundations/descriptive-statistics.md)
>
> The mean, median, standard deviation and quantiles of a data set.

> [card] [Expected value](https://quantumine.net/learn/learn/foundations/expected-value.md)
>
> The average profit or loss per bet, and why a positive expected value still leaves some people in the red.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.