GenerateRandomSearch

Balls in Bins Simulator

Throw fifty balls into fifty bins and you might expect one each. What you actually get is a fullest bin holding three or four, and about a third of the bins empty — the fraction tends to one over e. That lumpiness is why naive load balancing disappoints and why hash tables collide sooner than intuition suggests. The expected number of empty bins has an exact formula, and it is reported next to what actually happened.

What this generator does

Throws each ball into a bin chosen uniformly at random, repeated over many runs. It reports the average fullest bin against what an even split would give, and the average number of empty bins against the exact expectation.

How to use this tool

  1. Choose how many balls and how many bins.
  2. Predict the fullest bin and how many bins stay empty.
  3. Run it, and compare against the even share and the formula.
  4. Try equal numbers of balls and bins — the classic case.

Understanding the controls

How many balls
Up to 200. Equal numbers of balls and bins is the classic case where about a third of bins stay empty.
How many bins
Up to 100. Fewer bins than balls raises the fullest load sharply.
How many runs
From 100 upwards, capped at 3,000 here since each run touches every ball.
Seed
Reproduces the same allocation exactly, which matters when a particularly lumpy run is worth showing someone.

Common use cases

  • Showing why random load balancing leaves hot spots
  • Estimating hash collisions before building a table
  • Teaching the occupancy problem with visible counts
  • Capacity planning where work arrives at random
  • Reproducing a specific allocation from a seed

How this generator works

Each ball picks a bin uniformly. The check confirms the example run accounts for every ball, that the fullest bin is never below the even share — which would be impossible — and that the observed empty count sits near the exact expectation of bins times one minus one over bins, to the power of the balls.

Randomness and fairness

The allocation is random; the expected empty count is exact arithmetic. Seeded runs reproduce and are therefore explicitly not cryptographically secure. Unseeded, the browser's cryptographically secure generator throws the balls.

For how randomness is produced across the whole site, see how Generate Random works.

Limitations and good to know

  • Bins are chosen uniformly. The two-choices trick, which cuts the maximum load dramatically, is not modelled.
  • Only the first run's bin counts are shown in full; the rest are summarised.
  • Runs are capped at 3,000.
  • The maximum load is reported as a mean rather than a distribution.
  • Allocations are discarded when you leave; seed a lumpy one worth showing.

Privacy and your data

The allocation runs in your browser. No results or settings are sent anywhere or kept.