Hash Table Scenario Generator
Collisions start far earlier than people expect — twenty keys in fifty buckets will usually collide, for the same reason twenty-three people usually share a birthday. This shows the whole table: which keys landed where, how long the worst chain got, and how many buckets stayed empty. Lookup costs the chain length, so the longest chain is the number that matters, not the average.
What this generator does
Draws distinct keys and files each into bucket key-modulo-buckets, keeping chains in insertion order. It reports the load factor, the collision count, the longest chain and the number of empty buckets.
How to use this tool
- Choose how many keys and how many buckets.
- Predict how many collisions you will get.
- Generate, and look at the longest chain rather than the average.
- Push the load factor past one and watch the chains grow.
Understanding the controls
- How many keys
- Between 4 and 24 distinct numbers, all inserted before anything is measured.
- How many buckets
- Between 2 and 40. The ratio of keys to buckets is the load factor, and it is what drives everything else.
- Seed
- Reproduces the same keys exactly, so two bucket counts can be compared on identical data.
Common use cases
- Showing the birthday problem in its hash-table form
- Choosing a bucket count before building a table
- Worked separate-chaining examples with real numbers
- Test data for a hash table implementation
- Reproducing the same key set from a seed
How this generator works
Modulo hashing is used deliberately because it makes the bucket-count choice visible — a poor divisor clusters keys badly. The check confirms every key sits in the bucket its hash names, that the table's contents match the keys inserted, and recounts the collisions, the longest chain and the empty buckets from the finished table rather than trusting the running totals.
Randomness and fairness
The keys are random; where they land is arithmetic. Seeded scenarios reproduce and are therefore explicitly not cryptographically secure. Unseeded, the browser's cryptographically secure generator draws the keys.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Separate chaining only — open addressing behaves quite differently as the load factor rises.
- Modulo hashing on small integers, which is not what a production hash function looks like.
- No resizing is modelled, though that is what real tables do at high load.
- Keys are distinct, so duplicate-key handling does not arise.
- Scenarios are not stored between visits.
Privacy and your data
Keys and the table are generated in your browser. Nothing about the scenario or your seed leaves the page.
Related generators
- Balls in Bins SimulatorRandom allocation is far lumpier than it looks: the fullest bin against the even share, and empty bins against the exact formula.
- Bloom Filter GeneratorFills a Bloom filter and measures its real false-positive rate against the predicted one, with every inserted item proved still present.
- Trie GeneratorPrefix trees over words chosen to overlap, with the storage saving measured and the contents checked in both directions.
- Binary Heap GeneratorMin or max heaps built one insertion at a time, shown level by level, and drained to prove they sort.
- Random Matrix GeneratorA random 3x3 grid of numbers, for maths practice or placeholder data.