What is a random seed?

A random seed is the starting value that determines a random number generator's entire output sequence, letting a randomized process like HNSW construction be rebuilt identically on demand.
Created: Updated: 3 min read

A random seed is the starting value fed into a computer’s random number generator that determines the entire sequence of “random” values it will produce, and fixing that seed is what turns an otherwise unpredictable process, like HNSW‘s random level assignment, into one that can be run again and again with exactly identical results.

Why would a computer’s randomness need a starting value at all?

Computers don’t generate truly unpredictable randomness the way a physical process like a coin flip does — instead, they run a deterministic calculation that produces a sequence of numbers designed to look statistically random, and that calculation always starts from some initial input value called the seed. Given the exact same seed, the exact same generator will always produce the exact same sequence of values in the exact same order, every single time it’s run. This might initially seem to defeat the purpose of randomness, but it’s actually what makes computer-generated randomness practically useful: the output looks and behaves randomly for statistical purposes, while still being fully reproducible whenever that turns out to matter.

Why does reproducibility from a fixed random seed matter for a randomized data structure like HNSW?

HNSW‘s random level assignment, covered elsewhere in this glossary, relies on drawing random values to decide each vector‘s highest layer, which means the graph‘s exact shape technically depends on whatever sequence of random values got used during construction. Fixing the random seed before building an index means that sequence becomes fully reproducible, so rebuilding the same index from the same data with the same seed produces the exact same graph structure every time, rather than a structurally different graph on each rebuild, covered in this site’s coverage of reproducible tuning methodology. This matters enormously for debugging and for benchmarking, where being able to compare two runs meaningfully requires ruling out random variation in the graph’s construction as a confounding factor.

Does fixing the random seed change how well the resulting graph actually performs?

No — a fixed random seed only removes the run-to-run variability in exactly which random values get produced, it doesn’t change the underlying probability distribution those values are drawn from or bias the outcome toward better or worse performance in any systematic way. A graph built with a fixed seed still has the same overall statistical properties, such as the same expected layer proportions covered in this glossary’s page on expectation in probability, as one built with an unfixed seed — the only difference is that the fixed-seed version can be rebuilt identically on demand, while the unfixed version would produce a structurally different, though statistically similar, graph on each rebuild.

A random seed is the practical tool that reconciles HNSW’s reliance on randomness with the need for reproducible, comparable results across repeated runs. From here, the pages on random level assignment and on reproducible tuning methodology cover the specific places this reproducibility actually gets put to use.