Skip to content
AI-grafen
CBuilderStatistics and probability· about 30 min· fundamentals that rarely change· verified 2026-09-20· EN

Relative frequency and the law of large numbers

Simulate many trials and observe how the frequency converges to the probability.

Prerequisites

Intuition

Relative frequency = the number of times an event occurred divided by the total number of trials.

If you roll a die 30 times and get four sixes: 4/30 ≈ 0.13. The probability is 1/6 ≈ 0.167. They are not the same — but they are close.

The law of large numbers: the more trials you run, the closer the relative frequency gets to the true probability.

Number of rollsSixesRelative frequency
3040.133
300570.190
3,0004860.162
30,0005,0120.167

Code

import random
random.seed(0)

for n in (30, 300, 3_000, 30_000):
    rolls = [random.randint(1, 6) for _ in range(n)]
    print(n, round(rolls.count(6) / n, 3))

Two common misconceptions:

  1. «We have gotten four heads in a row, so tails must come next» — no. The coin has no memory. Each flip is still 50/50. This is known as the gambler's fallacy.
  2. «After 1,000 flips, it must be exactly half» — no. The proportion approaches 0.5, but the difference in counts can easily grow.

This is exactly why we test models on many examples: with only 20 test cases, random variation is larger than the difference between the models.

Mastery means

  • Calculates relative frequency from trials
  • Explains that the frequency approaches the probability as the number of trials increases

Sign in to do the exercises and build your mastery up.

Sources

All the sources and licences