The seed starts the run
In Lesson 3.7, you saw how a source of uncertainty can supply seed material. The seed initializes the generator’s internal state, the working information it updates from one request to the next. From the same starting state, following the same rules and giving the same requests gives the same results, as long as no fresh input is added. A process like this is deterministic.
The toy uses a six-state loop. In state A, a request returns byte B6 and changes the state to B. The first three requests from seed A take the state from A through B and C to D. Start from seed D instead and the first three steps follow a different part of the loop. Each pair of hex digits is one byte, or eight bits, as in Lesson 3.1.
| Seed | State after three requests | Output bytes (hex) |
|---|---|---|
| A | D | B6 29 E3 |
| D | A | 74 0D C8 |
Restart from A and the toy returns B6 29 E3 again. Bytes can look irregular and still be completely predictable once you know the state and the rule.
What makes a generator suitable for keys?
Pseudorandom describes output made by a deterministic rule that is designed to resemble random output. In the toy, seeing 29 tells you the next state is C, so you can predict E3. A real generator for keys must keep past output from giving away its state or the next bytes.
A cryptographically secure pseudorandom number generator (CSPRNG) uses a cryptographic algorithm and starts with seed material that is hard for an observer to guess. Its internal state stays secret. It can supply many bytes by updating that state, without needing a fresh measurement for every byte. Even someone who has seen earlier output should need an impractical amount of computing to predict future output when the generator is properly seeded and its state remains secret. Systems can also refresh the state with fresh entropy through a process called reseeding. See NIST’s recommendations for deterministic random bit generators.
For real keys and random secrets, rely on your platform’s cryptographic randomness. In a browser, use crypto.subtle.generateKey() for supported key types. Use crypto.getRandomValues() when you need raw random bytes, such as a secret for the paper vote in Chapter 5. See the Web Cryptography specification.
Check your understanding
A generator starts from a seed printed in its documentation and takes no other unpredictable input. Its output looks irregular. Why would those bytes make poor keys?
Show the answer
Anyone with the seed and the generator’s public rules can reproduce the output if they know the requests. A convincing-looking pattern is no guarantee of unpredictability. Real keys need a cryptographic generator properly seeded with material an observer cannot guess.