GenerateRandomSearch

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

  1. Choose how many keys and how many buckets.
  2. Predict how many collisions you will get.
  3. Generate, and look at the longest chain rather than the average.
  4. 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.