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
- Choose how many balls and how many bins.
- Predict the fullest bin and how many bins stay empty.
- Run it, and compare against the even share and the formula.
- 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.
Related generators
- Coupon Collector SimulatorHow many random draws it takes to collect a full set, against the exact harmonic-number expectation.
- Monty Hall SimulatorPlay the switch-or-stay problem a door at a time, or run it thousands of times with the exact theory and the observed rate reported separately.
- Random Number GeneratorGenerate one or many random numbers within any range, with optional duplicate control and sorting.
- Makespan Scheduling Problem GeneratorJobs across identical machines, scheduled longest-first, with two lower bounds that often prove the schedule optimal.