Published · · Last reviewed · · 6 min read

English · 한국어

Same seed, same result: reproducible random numbers

Computer random numbers have a starting point called a seed, and starting from the same seed gives the same numbers in the same order. In the Lottery Lab, if you set the seed to 2026 and draw Lotto 6/45 five times, you get 6-8-10-24-33-43, 6-12-14-19-29-42, 1-12-18-21-28-38, 5-12-15-24-25-43 and 14-15-19-28-43-44 every time. Random and yet repeatable sounds contradictory, but this property is very useful in simulation and testing, and in other places the same property is a danger. This page explains what a seed is, what must be the same to get the same result, and why the range of seeds is a limit.

The same seed gives the same result

The Lab's random engine uses a fast generator formula called xoshiro128**. When the user supplies a seed string it is turned into four 32-bit numbers as the starting point; when the seed is left empty the starting point comes from the browser's secure random source. Below, Lotto 6/45 was drawn twice from the same seed.

The first two Lotto 6/45 draws per seed in the Lab engine (each seed run twice for five draws; all identical)
SeedFirst drawSecond drawSame on repeating?
20266-8-10-24-33-436-12-14-19-29-42same
20275-16-35-37-41-4418-19-27-30-38-41same
lottoflick12-19-21-22-29-408-12-23-28-39-45same

Seeds that differ by just 1, like 2026 and 2027, give results with no relation. Neighbouring seeds do not give neighbouring results. As a check I took the first draw for seeds 0 to 99,999 (as strings), 100,000 draws, and counted each number: against an expected 13,333 the least frequent number appeared 13,093 times and the most frequent 13,480, with a chi-square of about 34.2, a level normal for an even draw (an approximation for 44 degrees of freedom).

Where the same result is useful

Reproducing a simulation. The Lottery Lab states in its report that with a seed the same game, same sampling method and same number of draws give the same counts. Others can check the same result, so putting the seed in an explanatory text lets readers run it again themselves.

Finding bugs. When a program sometimes gives a wrong answer but randomness prevents reproducing it, fixing the seed lets you produce the same error again and again.

Comparing methods. Using the same seed (the same random sequence) for two methods compares the methods rather than the luck of the random numbers.

What must match for the same result

The seed alone is not enough. A seed gives "the same random sequence"; the same numbers appear only if the way the sequence is turned into numbers is the same too. Taking the sequence from seed 2026 above and turning it into numbers with the remainder operator (% 45 + 1) gives 33, 33, 4, 31, 33, 29, a method in which numbers can repeat and which is also biased. Starting from the same random numbers, a different conversion gives a completely different result. The position in the sequence must also match (the fourth draw uses numbers after the first three), and so must the engine version. That is why the Lab report also records a version of the sampling method.

How far a seed can reach

If the seed is a 32-bit integer there are only 4,294,967,296 different seeds. One Lotto 6/45 combination is one of 8,145,060, so one draw can be covered almost entirely by seeds. But ten draws in a row have 8,145,06010 possible outcomes, about 1069. A 32-bit seed can reach only 4.3 billion of them, so nearly all outcomes can never be produced however the seed changes. The Lab turns the seed string into a 128-bit state (four 32-bit words) and reaches a far larger range, but how varied the short strings people actually type (at most 64 characters) will be is up to them.

Seeds can also coincide. If different people each choose a 32-bit seed at random, the same structure as the birthday problem produces overlaps. With 10,000 people the chance of at least one overlap is 1.2%, with 100,000 people 68.8%, and with a million practically 1 (the same calculation as in The birthday problem).

Check it yourself

The tool below feeds a seed to a simple linear congruential generator (LCG) built for this site's explanations and makes six numbers. The same seed always gives the same numbers, and the button below draws different numbers each time from the browser's secure random source.

This tool needs JavaScript.

In this explanatory generator seed 2026 gives 33, 9, 32, 26, 24, 24 and seed 2027 gives 8, 34, 34, 7, 9, 34. As you can see from 24 appearing twice and 34 three times, this demo is not a Lotto draw of six distinct numbers; it shows the sequence a seed produces. That is why numbers can repeat.

Where the same result is dangerous

A predictable seed is a problem where unpredictability matters. If the seed is something like the time or a small integer, anyone can put in the same seed and produce the same sequence. For a 32-bit seed, trying all 4,294,967,296 values is a size ordinary computers can handle. So for passwords, cryptographic keys, or draws that must be fair, one uses the secure random numbers provided by the operating system rather than a generator whose seed can be set to a publicly knowable value. That this site's number generator uses the browser's secure random source is explained from the code in How computers make random numbers, and the Lab also starts from the secure source when the seed is empty.

For people to believe a draw is fair they usually need both "unpredictable" and "verifiable afterwards", and a seed is a balancing act between the two. If the seed is fixed and published before the draw (a commitment) and the same seed is used afterwards to reproduce the result, verification is easy, but whoever chose the seed can know the result in advance. Who chooses the seed, when and how, becomes the heart of the fairness question (How a lottery draw is kept fair).

Leaving a reproducible result

When writing a simulation result in an article or report, to let others get the same result you should record these together. First, the seed (if a string, its spelling and capitalisation). Second, which game and which rules were run (for example Lotto 6/45, 6 of 45). Third, how many draws. Fourth, the sampling method and the program version. If any of these four differs, the same seed can give a different result. The Lottery Lab's JSON report is set up to carry the seed, the number of draws and the method version together.

Recording the seed also lets you check later whether the program still behaves as intended by asking "does the result I got then still come out now?". Some of this site's tests pin the result for a fixed seed for the same reason. If the seed is the same and the result has changed, it is a sign that the code has changed.

Questions that come up

"Is a fixed-seed result still random?" Statistically it looks random, but the same seed gives the same result, so it can be predicted. "Looks random" and "unpredictable" are different.

"Are there good seeds and bad seeds?" A good generator is built so that the statistical properties are the same whatever the seed. In the check above the first draws of 100,000 neighbouring seeds came out evenly. There is no attempt to choose results through seeds: trying seeds until you find numbers you like is the same as choosing the numbers yourself.

What is specific to this engine

The figures on this page come from running the Lab engine and the explanatory LCG exactly as they are in this site's code. If the engine changes, the result for the same seed changes. That trying all 32-bit seeds is feasible "on an ordinary computer" is a general statement about size; this page did not time it. A general account of cryptographic safety is beyond the scope of this page and is not covered in detail.

Sources and verification