
Pseudorandom Number Generator
A pseudorandom number generator is a computational procedure that produces sequences of numbers that look random but are in fact precisely calculated. Starting from a seed value, it always produces the same sequence again — which makes programs reproducible, but suitable for security purposes only with special methods.
Computers cannot roll dice. They follow computational rules, and the same rule always yields the same result given the same starting conditions. Yet programs constantly need numbers that appear unpredictable: for games, for simulations, for encryption. The solution is a pseudorandom number generator, or PRNG for short. It takes a single starting number and computes from it a long chain of further numbers. This chain looks like randomness, but is entirely determined — hence the word “pseudo,” meaning “apparent.”
Why apparent randomness is often better than true randomness
True randomness can be obtained from physics, for instance from the electronic noise of a component or from radioactive decay. That is costly and slow. A PRNG, by contrast, produces millions of numbers per second and needs only a few computational steps per number. For the vast majority of applications, this is the more practical route.
The second advantage sounds paradoxical at first: a PRNG is repeatable. If you store the starting value, known as the seed, you get exactly the same sequence of numbers again. That is precisely what researchers need when they want to rerun a climate simulation or a machine learning experiment. With true randomness, every run would be different and an error would be almost impossible to find.
In AI development, the seed is therefore a standard tool. It determines how the initial values of a neural network are randomly drawn and in what order the training data arrives. Two training runs with the same seed produce the same model. Without this control, comparisons between two approaches would be worthless, because one could never know whether a difference stemmed from the method or from chance.
From seed to number chain
A PRNG keeps track of an internal state, that is, a number or a group of numbers. On every request, it transforms this state using a fixed formula and outputs part of it as the result. The new state then serves as the basis for the next number. One simple classical method multiplies the state by a large constant, adds a second one, and keeps only the remainder of a division. The result appears to jump wildly through the number space.
Because the state can only take on finitely many values, the sequence eventually repeats. This length until repetition is called the period. Good generators have astronomically long periods; the widely used Mersenne Twister does not repeat until roughly 2 to the power of 19937 steps. In practice, this end is never reached.
A common misconception is that a long cycle already implies security. For many standard generators, a few hundred observed outputs suffice to reconstruct the internal state and predict all future numbers. For passwords or keys, one therefore needs cryptographically secure generators. These use methods for which the reverse path from output back to state is practically impossible to compute.
Where the dice are rolled everywhere
Every video game with a random map or random loot drop uses a PRNG. Some games even display the seed so that players can share the same world — in Minecraft, this is exactly a well-known feature. The order of tracks in music apps or the shuffling of cards in online games also works this way.
In science, PRNGs power Monte Carlo simulations. Here, a process — say, the motion of particles or the development of a stock price — is computed very many times using random values. The average of the runs yields an answer that could not be obtained analytically.
In AI-related news, the term usually appears indirectly. If a chatbot gives different answers to the same question, this is due to a random selection among the most probable next words. If the seed is fixed, the answer becomes reproducible. And when a security incident is traced back to a “weak random number generator,” someone has used a method for keys that is only suitable for games.