Pseudorandom Numbers and the Seed: Why Computer Randomness Is Not Random, and How to Reproduce It
A computer's numbers are not random. Every number a computer produces comes out of a written down rule applied to the number just before it, so fixing the starting number fixes the entire run in advance. Multiply by seven, take the remainder on eleven, begin at one, and the run is 7, 5, 2, 3, 10, 4, 6, 9, 8, 1, then 7 again, for ever.
Two rules do all the arithmetic below. Multiply by seven and take the remainderWhat is left over when one whole number has been divided into another as many whole times as it will go. Eleven goes into forty nine four times, and five is left over. on eleven for the small rule; multiply by 16,807 and take the remainder on 2,14,74,83,647 for the working one. Each figure sits beside the starting number that turned it out, so any of them can be made again by hand: a pen is enough for the small rule, and a calculator holding ten digits is enough for the large one.
Are a computer's random numbers actually random?
No. Not slightly, not mostly, not in a technical sense that only a specialist would object to. A computer producing what it calls a random number is running a short piece of arithmetic on the number it produced last time, and returning the result. Nothing is being sampled. Nothing is being observed. There is no coin and there is no dice cup anywhere inside the machine.
The word for this is pseudorandom, and most readers meet it as throat clearing, so the word is worth stopping on before anything else. Pseudorandom sounds like a lawyer's hedge: the numbers are random, and pseudorandom is said only in case somebody sues. The word is nothing of the kind. Pseudorandom is a flatly accurate description, and it means the numbers only look unpredictable from outside, to somebody who has not been shown how they are made. Show them the rule, tell them where the run began, and they can set out the entire run in advance, in order, on paper, before a key is pressed.
Think of a very long song heard a thousand times. Played to a stranger, every note surprises. Played to the person who knows it, nothing does. The notes did not change. Only one of the two listeners holds the rule that produces them. A generator's streamThe run of numbers a rule turns out, in the order it turns them out. The first number, then the second, then the third, on and on for as long as it is asked. is that song. The whole stream is written before anyone hears a note of it.
Almost everything that goes wrong later comes from forgetting this. A person who believes the numbers are genuinely unpredictable will treat two runs from neighbouring starting numbers as two independent draws on the world, will treat a run that repeats itself as a coincidence, and will treat the ability to reproduce a result as a lucky accident rather than as the plain consequence of arithmetic. All three are wrong in the same direction, and each of the three is taken in turn below.
Machines describe the numbers they hand out as pseudorandom. Is the prefix there to cover somebody, or does it report what the machine actually does?
Where does each number actually come from?
Here is the whole idea, at a size that can be done in the head: take a number, multiply it by seven, divide by eleven and throw the whole elevens away. The leftover is the next number, and the same arithmetic is then done to it.
Starting at 1: seven times one is seven, and no eleven fits inside seven, so all seven is left over. The first number is 7. Seven times seven is forty nine. Four elevens make forty four, and five is left over, so the second number is 5. Seven times five is thirty five, three elevens make thirty three, and two is left over, so the third is 2. Seven times two is fourteen, one eleven makes eleven, and three is left over, so the fourth is 3. Four lines of arithmetic build a random number generator. Doing it by hand rather than pointing at a ready made one is the entire point.
The small rule is called the hand generator, and it exists for one reason: it can be cranked by hand. Everything about it fits on a single sheet, and nothing about it has to be taken on trust. The multiplierThe number every value gets multiplied by before the remainder is taken. Here it is seven. is 7 and the modulusThe number the remainder is taken on. It fixes how big the world is that the arithmetic is allowed to move around in, because no remainder can ever be as large as the modulus itself. is 11.
The rule these notes actually run on is called the stated generator, and it is the same two steps at a size no pen enjoys: multiply by 16,807, then take the remainder on 2,14,74,83,647. That is all. There is no third step and no hidden ingredient. For a uniform drawA number somewhere between zero and one that is as likely to land in one stretch of that line as in any other stretch of the same width. rather than a whole number, the remainder is divided by the same 2,14,74,83,647. A remainder is never as large as the number it was taken on, so the result can never fall below zero or rise above one.
The hand generator, multiply by seven and take the remainder on eleven, has just produced 3. The next two numbers can be worked out on paper before the answer is revealed.
What is a random seed, and what does it actually control?
The seed is the starting number. The definition is that short. Almost every wrong belief about generators is really a wrong belief about the seed, so the seed earns a section rather than a line.
The ground is worth clearing. A seed supplies no randomness, sets no quality level and moves the run neither closer to nor further from unpredictable; all it settles is the entry point into a run the rule has already written out in full. A larger seed does not give better numbers. An odd seed is not luckier than an even one. A seed picked by looking at the clock is not more honest than a seed picked out of fondness for the number. None of these touch the rule, and the rule alone decides what the numbers are.
Consider a wall clock with a second hand. Started at twelve, it goes 1, 2, 3, all the way round to 60 and back to 1. Started at forty, it goes 41, 42, 43, round past 60 and on to 39. The clock has not changed. Neither has which numbers appear on its face, or the order they come in, or how long it takes to come round again. One thing changed: where the hand was pointing when it was let go. A seed is that starting point, and the word oversells it. A seed in the ground grows into a plant that was not there before. A seed here starts nothing growing; it only says which door the run was entered by.
Now the part people find surprising, and then find obvious about four seconds later. Because the seed fixes the whole run, running the same generator from the same seed a year apart on a different machine gives the identical numbers. Not similar numbers. The same numbers, in the same order, to the last digit. Repeatability is the reason a seed is worth writing down at all, and it turns a simulated result into something another person can check rather than believe.
The instinct this offends is worth naming. Reproducibility feels like cheating: if the machine can be made to produce the same result every time, surely the randomness has been removed and the answer means nothing. The answer is that the randomness was never there to remove. A simulated run offers a wide set of possibilities explored quickly, and exploring the identical set again tomorrow is a strength, not a compromise. A run nobody can repeat is not more honest, only harder to argue with, and those are two different things.
Do ten different starting numbers give ten different sets of numbers?
The question turns the seed from a definition into a countable fact, and the hand generator is small enough to answer it completely rather than by example.
There are ten seeds available, the whole numbers 1 to 10. Zero is not among them, and the reason takes one line: seven times zero is zero, and the remainder of zero on eleven is zero, so a run seeded at zero produces zero for ever and never leaves. Every other starting number does something. Seed 1 gives 7, 5, 2, 3, 10, 4, 6, 9, 8, 1. Seed 2 gives 3, 10, 4, 6, 9, 8, 1, 7, 5, 2. Seed 5 gives 2, 3, 10, 4, 6, 9, 8, 1, 7, 5.
Read those three again, slowly. Every one of them contains all ten values. Every one of them contains each value exactly once. And every one of them puts those values in the same order as the others, entered at a different point. The ten seeds do not give ten sets of numbers; they give one set of numbers, entered at ten different places, and the seed chooses only the place.
The ring is the honest picture of what a generator is. Everything a reader might want to call random about the hand generator is a property of the ring, and the ring was decided the moment somebody chose 7 and 11. All ten seeds are already on it. Choosing one is choosing a doorway in a corridor that runs in a circle, and once inside, the walk passes every other doorway in the same order no matter which one it began at.
Written out in full, all ten runs look like this. The left column read downwards is the ring itself, in the order the rule visits it.
Seed 8 gives 1, 7, 5, 2, 3, 10, 4, 6, 9, 8. Without cranking anything, say what seed 4 gives.
The panel below is about to go from a seed of 1 to a seed of 6. The question is worth settling before it moves: will it show a fresh set of ten numbers, the same ten rearranged, or some of each?
Walk into the ring by any of its ten doors
One control and ten settings. Every setting redraws the ring, the run and the marks on the line from zero to one. Watch which of the three actually changes.
Educational illustration. The hand generator is a tiny rule whose whole loop fits on one screen, and no real run would ever use it. The stated generator is the same two steps at a far larger size: multiply by 16,807, take the remainder on 2,14,74,83,647. Randomness that has to withstand an opponent, such as the sort protecting keys, answers to a separate set of requirements and is covered separately.
What is a period, and what does a short one cost?
The ring has ten steps. After ten multiplications the hand generator is back at the number it started from, and from there it repeats itself exactly. The count has a name: the period. Because the period is ten, the eleventh number the hand generator produces is fixed before the first one is drawn, and it is the same as the first.
Divided by eleven and marked along the line from zero to one, the ten values show something uncomfortable. The ten marks are perfectly, mechanically even. The gap between neighbouring marks is identical everywhere, and so are the two gaps at the ends. Their sum divided by ten is exactly one half, not approximately, not to four decimal places, but exactly, every whole loop, from every seed.
The evenness is worth sitting with, and it inverts the instinct. Perfect evenness feels like a good report card. Perfect evenness is the opposite. Ten numbers from a genuinely unpredictable source arrive with clumps and gaps, and an average of exactly one half would be astonishing. The lower line in the figure is what ten draws are supposed to look like: four bunched near the left, a long bare stretch through the middle, and no two gaps alike. The hand generator is too tidy to be mistaken for unpredictable, and it is exactly that tidiness that a short period produces.
So what does a short period actually cost? Asked for eleven numbers, the hand generator makes the eleventh a repeat of the first. Asked for a hundred, it returns ten copies of the same ten numbers. Anything computed on those hundred numbers is a statement about ten numbers dressed up as a statement about a hundred, and every measure of how uncertain the answer is comes out far too confident, counting a hundred pieces of evidence where only ten exist.
The stated generator solves this in the least clever way available: the same two steps, at a size where the problem cannot arise. Its multiplier 16,807 is seven multiplied by itself five times. Its modulus 2,14,74,83,647 is two multiplied by itself thirty one times, less one, and it is a prime numberA whole number above one that divides evenly by nothing except one and itself.. The multiplier turns out to be a primitive rootA multiplier that touches every non zero value before it comes back to where it began. It is what makes a loop as long as it can possibly be rather than a short one hiding inside a large modulus. of that modulus, which is the technical way of saying its ring is as long as the modulus allows: 2,14,74,83,646 values before anything repeats.
Put a size on that. The busiest run in these notes draws twelve numbers for each of 2,56,000 paths, or 30,72,000 numbers in total. Against a period of 2,14,74,83,646 that is roughly one seven hundredth of the way round the ring. There is no realistic chance of the run wrapping and quietly reusing values. A rule this simple stays worth using once it is scaled up for exactly that reason.
The hand generator's ten values average exactly 0.5000 over a whole loop, from every seed, with no variation at all. Is that a point in its favour?
Two colleagues run the stated generator, one from a seed of 12345 and one from 12346. Commit to both halves before reading on: how alike will their first drawn numbers be, and how alike will their second ones be?
What happens when two people pick starting numbers one apart?
Run from a seed of 12345, the stated generator, multiply by 16,807 and take the remainder on 2,14,74,83,647, produces 0.096617, then 0.833995, then 0.947702. Run from a seed of 12346, it produces 0.096624, then 0.965532, then 0.703308.
Look at the first pair. The two numbers agree to four decimal places. Now look at the second. The second pair agrees on nothing. Moving one along in the starting number is not a small adjustment to a run, and the near match on that opening number is a real blemish in a rule this plain rather than a charming quirk.
The reason is one line of arithmetic, and it is worth doing rather than believing. 12345 multiplied by 16,807 is 20,74,82,415. 12346 multiplied by 16,807 is 20,74,99,222. Both are smaller than 2,14,74,83,647, so neither is touched by the remainder step at all, and the two results differ by exactly 16,807. Divided by the modulus, that difference is 0.0000078, about one part in 1,27,773. The first draw from neighbouring seeds is nearly identical because at the first step the rule has not yet had a chance to wrap around, and wrapping around is the only thing that separates anything.
From the second step onward it does wrap, and the two runs part company completely. The split is worth watching, and it kills two beliefs at once. The first belief is that neighbouring seeds give neighbouring runs, false from the second number onward. The second belief is that neighbouring seeds give completely different runs, false at the first number. Neither is true, and there is no simple relationship to fall back on.
The stretches drawn on the right of that figure are how a drawn number becomes a monthly changeThe per cent a price moves over one month, up or down. It is what a drawn number is turned into once a simulation has it, and how that turning is done is covered separately. for the Nakshatra unit, an invented traded unit used throughout these notes. Notice what those stretches do to the first pair: 0.096617 and 0.096624 both land in the same one, so both runs open on a monthly change of minus 4.00 per cent. The two runs are identical for a whole month before they diverge, and then they diverge into different stretches at the second draw and again at the third.
Somebody proposes rerunning the identical model from a fresh starting number and treating the second answer as an independent check on the first. Which of these has the exercise actually measured?
What does random enough mean when a rule makes every number?
If the numbers are produced by a rule, the word random cannot mean unpredictable, so it has to be given a working meaning. The working meaning is this: a run passes when it stands up to the same examinations a genuinely unpredictable one would be put through. Three of those tests matter more than the rest, and all three can be applied to the hand generator in the head.
The first test is share. Does every stretch of the line from zero to one get roughly the number of values its width deserves? The hand generator passes this one and then some. The spacing is suspiciously perfect, and that perfection is the failure described above.
The second test is memory. Having seen one number, is an observer any better placed to name the one after it? Here the hand generator collapses completely. Once a 7 has appeared, the next number is a 5 without any doubt, and that is true at every position, in every run, for ever. Nine values in, the tenth is known. Memory is the test a small generator cannot survive, and it is not a matter of degree: the information is total.
The third test is length. Will the run repeat inside the job it is about to be given? Asked for a hundred numbers, the hand generator repeats ten times over. Asked for the 30,72,000 numbers the busiest run in these notes needs, the stated generator does not repeat, with a factor of about seven hundred to spare.
So the honest defence of the stated generator has nothing to do with unpredictability. The defence is that it passes the three tests at the scale anything actually asks of it, while a rule of the same shape with a modulus of 11 fails the second and third outright. Random enough means exactly that: a claim about fitness for a job rather than a claim about the nature of the numbers. Formal statistical tests push much harder on all three questions, and running those tests properly is its own subject.
One boundary is worth marking off firmly. None of this reaches randomness built to resist an opponent, the kind that protects keys. Adversarial randomness sits under separate requirements entirely, and a rule whose whole run can be rebuilt from one number is precisely the wrong instrument for it. Neither rule described here should be carried anywhere near it.
The hand generator fails one of the three tests badly while the stated generator passes it. Name the test and say what fails, using two of the ten values.
What does somebody re-running the work actually need?
Reproducibility is where this arithmetic meets a desk. Somebody has produced a simulated result. Six months later a lender wants to see it again, or an analyst inherits the workbook, or a colleague wants to build on it. Which four facts have to have been written down for the second person to get the identical answer?
Four things, and they fit on one line. The rule. The starting number. How many numbers were drawn. And the order those numbers were used in.
The first three get written down almost by reflex. The fourth is the one people forget, and it is the one that quietly breaks things. Feed the identical numbers to the identical model in a different order and the result moves, so a log carrying the rule and the starting number but not the routing will not bring the answer back.
Picture a queue at a ration shop where the shopkeeper serves people in the order they arrive. Same people, same stock, same shop. Change the order of the queue and the last few get something different. Stock left over depends on who came earlier in the line. A simulated run is that queue. If the first drawn number went to the first month of the first path in one version and to the first month of every path in another, the numbers drawn were identical and the result is not.
An analyst or a lender asking for a reproducible result is asking for exactly those four fields. Not the answer, and not a promise about the method. Four fields, one line, and enough discipline to fill in the fourth.
Name the four things a run has to record if somebody else is going to get the identical answer back.
The failure: two seeds one apart, called an independent check
Two people on the same desk are told to run the model separately so that each result checks the other. One picks a seed of 12345. The other picks 12346. Sitting next door to somebody else's number feels like the plainest way to be visibly not copying them.
Their first drawn numbers are 0.096617 and 0.096624. Both numbers agree to four decimal places and read off the same monthly change of minus 4.00 per cent, so the two runs open identically. Their second numbers, 0.833995 and 0.965532, read off as 6.00 and 11.00 per cent, and from there the two runs share nothing.
Between them they have built neither a check nor a comparison, only two arbitrary runs standing in a relationship nobody in the room is able to describe. When the two answers come out different, and they will, nobody can say whether the difference means anything. Is the method sensitive? Is one of them wrong? Is this ordinary drift? There is no way to tell, and the exercise that was supposed to create confidence has created an argument instead.
The fix is not a better seed. The fix is to stop treating the seed as a variable worth changing. An independent check varies the shape drawn from, or the method, or the data, and holds the seed fixed, so any difference observed is caused by the one input that changed. Varying the seed measures exactly one thing: how far a run wanders on its own when nothing of substance has moved. Measuring that wander is occasionally worth doing, and it is never a check on anybody's work.
Covered separately. Everything a simulation goes on to do with these numbers is covered separately, along with the step that turns a drawn number into a monthly change. The discipline of declaring a starting number before a run rather than after seeing the answer is covered separately as well, and that is where the reporting rules live. Randomness built to resist somebody guessing it, for keys or for anything an opponent would want to reconstruct, sits under a separate set of requirements. The formal statistical tests of a run are named above and carried out elsewhere.
How can each of these claims be disproved?
Whole number arithmetic answers to no regulator, no exchange and no published series. Every claim made for the two rules can be settled by doing the arithmetic instead, and each row below names the working that one takes.
| The claim | How it is checked | What checking it takes |
|---|---|---|
| Seven times a number, remainder on eleven, from a start of 1 gives 7, 5, 2, 3, 10, 4, 6, 9, 8, 1 and then begins again | Do the ten multiplications in order | A pen and ten lines of working |
| All ten starting numbers give ten orderings of that same set of values | Repeat those ten lines nine more times, once from each start | A pen and a quiet half hour |
| Dividing the ten values by eleven and averaging gives exactly one half | 1 to 10 add to 55, then divide by 10 and by 11 | One line |
| 16,807 is seven multiplied by itself five times, and 2,14,74,83,647 is two multiplied by itself thirty one times, less one | Multiply both out | A calculator holding ten digits |
| Seeds 12345 and 12346 give first numbers 0.096617 and 0.096624, differing by exactly 16,807 before the division | Multiply each seed by 16,807 and confirm both products sit below the modulus, so the remainder step leaves them alone | Two multiplications and one subtraction |
| 2,14,74,83,647 divides by nothing but one and itself, and 16,807 touches every non zero value before returning | Trial division for the first, and a check against each of the prime factors 2, 3, 7, 11, 31, 151 and 331 for the second | A short script; neither number is worth taking on trust |
The Nakshatra unit and the fifty month record behind it are invented.
Educational material. Not advice on any investment, tax, budget or market position.
