50% chance after draws, ≈ 1.18 √N
Average wait
Experiments

More information about the collision paradox

Collision paradox

How many random values can you draw before one repeats? Far fewer than you think. With 10,000 PIN codes an even chance of a duplicate comes after only 119 random codes, with 2³² hash values after 77,164, and in general after about 1.18 times the square root of the number of possible values. Pick a space, from 365 birthdays to the 2¹²² values of a UUID or a number of your own, draw values until the first repeat, run the experiment up to 5,000 times and watch the waits pile up along the theory curve of the birthday problem. Pick a space of N equally likely values, from 365 birthdays to 2¹²² UUIDs, and draw random values from it until one comes up twice. Every experiment is repeated hundreds or thousands of times: the chart compares how long the waits were with the theory curve, the chance of at least one repeat among n draws. Draws sets n for the Chance tile and the orange marker. Play shows the first experiment draw by draw, then the others quickly; Skip shows them all at once, Reset goes back to the start of the same run and New run draws new random numbers. Spaces whose expected wait is above 100,000 draws are too big to simulate, so the chart shows the theory only.

How it works

  1. Choose a space under Values: birthdays, PIN codes, 4-letter words, lottery tickets, 32-bit or 64-bit hashes, 8-letter passwords, UUIDs or your own number of values.
  2. Press Play to draw random values one by one until one repeats, then watch hundreds or thousands of experiments follow.
  3. Compare the share of experiments with a repeat by n draws with the theory curve, and read the 50% point and the average wait in the tiles.
  4. Move Draws to read the chance of a repeat for any number of draws, and save the picture or open it in the photo editor in layers.

Why repeats come so soon

A repeat needs only two draws to match each other, not one draw to match a value chosen in advance. Among n draws there are n(n − 1)/2 pairs, and each pair matches with a chance of 1 in N, so once the number of pairs approaches N a repeat becomes likely. The exact chance that all n draws differ is (1 − 1/N)(1 − 2/N) … (1 − (n − 1)/N), close to e^(−n(n − 1)/2N). It falls to one half after about 1.1774 √N draws: 23 for 365 birthdays, 119 for 10,000 PIN codes, 3,361 for the 8,145,060 tickets of a 6-of-45 lottery.

The experiment: draw until the first repeat

Each experiment draws uniform random values from 0 to N − 1 and stops at the first value that has come up before. The number of draws it took is the wait. Repeated hundreds or thousands of times, the waits form a skewed distribution that peaks near √N and averages √(πN/2) + 2/3: 24.6 for birthdays, 126 for PIN codes, 82,138 for 32-bit hashes. The share of experiments that have stopped by n draws follows the theory curve P(repeat among n), so the simulation and the formula can be compared directly. Spaces whose expected wait is above 100,000 draws are shown in theory only.

Hashes, passwords and random IDs

The square root decides how safe digital fingerprints and identifiers are. A hash of b bits resists collisions only up to about 2^(b/2) tries, which is why MD5's 128 bits give 64-bit collision security and why modern systems use 256-bit hashes. Random 32-bit IDs clash after tens of thousands, 64-bit IDs after billions, and the 122 random bits of a version 4 UUID need about 2.7 × 10¹⁸ of them for an even chance. PIN codes and passwords collide even sooner than the formula says, because people do not choose them at random.

Frequently asked questions

What is the collision paradox?

The birthday problem for any set of N equally likely values: random draws repeat much sooner than intuition suggests. An even chance of a repeat comes after about 1.1774 √N draws, so 23 for 365 birthdays, 119 for 10,000 PIN codes and 77,164 for 2³² hash values, not after half of N.

How is it different from the Birthday Paradox app?

The Birthday Paradox app fills a room with people and their birthdays. This app works with any space of values, from PIN codes and lottery tickets to 64-bit hashes and UUIDs, and runs the experiment of drawing until the first repeat thousands of times, so you can compare the distribution of the waits with the theory.

What do the tiles show?

50% chance after gives the fewest draws with at least an even chance of a repeat. Chance with n draws gives P(at least one repeat) for the Draws slider, with the expected number of matching pairs n(n − 1)/2N. Average wait is the mean number of draws until the first repeat in the experiments so far, beside the theory √(πN/2) + 2/3. Experiments counts the experiments shown.

Why can some spaces not be simulated?

Because the first repeat would take too long to reach. For 8-letter passwords the average wait is about 573,000 draws, for 64-bit hashes 5.4 billion and for UUIDs 2.9 × 10¹⁸. Above an expected wait of 100,000 draws the chart shows the theory only and the grid shows a sample of 1,500 draws, which almost surely contains no repeat.

What does this mean for hash functions?

A hash with b bits has about 2^(b/2) collision security, not 2ᵇ: this is the birthday attack. A 128-bit hash like MD5 is broken by a generic attack after about 2⁶⁴ tries, and real cryptanalysis broke MD5 and SHA-1 even faster. That is why SHA-256 and other 256-bit hashes are used today.

Can I use the picture?

Yes. Save gives a PNG, and the pencil opens the picture in the PictorX photo editor with the grid of values, the drawn values, the collision, the chart's axes, the simulated waits, the theory curve, the markers and the labels on layers of their own. Everything is simulated in your browser; nothing is sent anywhere.

Collision Paradox: how do I record a video?

Press the red Record button in the playback bar: it films what the stage shows. Press it again to stop, and the video is saved to your device. Recording is free; you only need to sign in. Without a subscription the video carries a small PictorX logo in a corner. The button beside Record opens the video options: the shape (as shown, square, story 9:16 or wide 16:9), the length (until you stop, or 5, 10, 15 or 30 seconds for social media) and the file: MP4, WebM or an animated GIF. You can add one of three music tracks: calm, bright or beat.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor