Game Tech Cab 029
Pseudo-Random Number Generators: How Code Turns a Seed Into Chance
- Reading minutes5 min

A pseudo-random number generator (PRNG) is an algorithm that turns a starting value, called the seed, into a long stream of numbers that behave as if they were random. "Pseudo" is honest labelling: the stream is fully determined by the seed, so the same seed always produces the same numbers. What makes a generator good is that, without knowing the seed or its internal state, nobody can tell its output apart from true chance or predict what comes next.
Digital casino games, video games, scientific simulations and encryption all lean on these generators. Here is how they work, why some are much stronger than others, and how a raw number becomes a card, a die face or a reel position.
Seed, state and step
Every PRNG has three parts:
- State: a block of numbers held in memory.
- Step function: a rule that turns the current state into the next state.
- Output function: a rule that turns the state into the number handed to the program.
The seed sets the very first state, and after that the generator just keeps stepping. Because the state has a fixed size, it must eventually return to a value it has held before, and from that point the whole sequence repeats. The length of that cycle is called the period.
A tiny generator you can run on paper
The oldest widely used design is the linear congruential generator, or LCG. Its rule: multiply the current value by a constant, add another constant, and keep the remainder after dividing by a modulus. Take a deliberately small version that multiplies by 5, adds 3, keeps the remainder after dividing by 16, and starts from a seed of 7.
The sequence runs 7, 6, 1, 8, 11, 10, 5, 12, 15, 14, 9, 0, 3, 2, 13, 4, and then returns to 7. Every value from 0 to 15 appears once before the cycle repeats, so this little generator reaches the longest period its modulus allows.
Now look at whether each number is odd or even: odd, even, odd, even, all the way round. The lowest bit flips like a light switch. That is a known weakness of LCGs whose modulus is a power of two, and it shows why looking random at a glance is not the same as passing statistical tests. Real LCGs use enormous constants, but the same structural patterns can surface in their low bits.
Three generator families compared
| Type | How it works | Strength | Weakness |
|---|---|---|---|
| Linear congruential | Multiply, add, keep a remainder | Very fast, tiny state | Patterns in low bits; easy to predict from a few outputs |
| Mersenne Twister | Large state array mixed with bit shifts | Enormous period of 219937 − 1 and good statistical quality | Its internal state can be rebuilt from enough consecutive outputs |
| Cryptographically secure (CSPRNG) | Built from ciphers or hash functions, seeded from unpredictable sources | Past outputs reveal nothing useful about future ones | Slower, although fast enough for games |
For a spreadsheet experiment, a Mersenne Twister is perfectly adequate. Wherever someone could gain by guessing the next number, as with encryption keys or games played for money, the cryptographic family is the sensible choice, because statistical quality alone does not prevent prediction.
PRNG vs TRNG
A true random number generator (TRNG) measures a physical process that is unpredictable in principle, such as electronic noise in a circuit. Its output cannot be replayed from a seed. TRNGs tend to be slower, and their raw output needs cleaning up before use, so many systems combine the two: hardware noise supplies unpredictable seeds, and a cryptographic PRNG stretches them into as many numbers as the software needs.
From a number to a game result
A generator usually produces large whole numbers, often 32 or 64 bits long. The game then maps them onto its own outcomes, and that mapping needs care.
The remainder trap
Suppose a game needs a die roll and takes a random byte (0 to 255), divides by 6 and keeps the remainder. Since 256 is not a multiple of 6, remainders 0 to 3 can each be reached 43 ways while 4 and 5 can be reached only 42 ways, so the die is very slightly loaded. The standard fix, called rejection sampling, throws away the values 252 to 255 and draws again, leaving exactly 42 ways for each face.
Shuffling a deck
A fair digital shuffle usually follows the Fisher–Yates method: walk through the deck and swap each position with a randomly chosen position at or beyond it. There is a subtle catch. A 52-card deck has 52! possible orders, a number with 68 digits, roughly 2226. A generator seeded with only 32 bits can reach at most about 4.3 billion of those orders, a vanishing fraction. Serious card software therefore needs a generator with far more state and far more seed entropy than that.
Reels on a slot
For a video slot, each generated number picks a stop on a reel strip, and the paytable decides what the combination pays. In browser slots the draw normally happens on the operator's server, and the animation you watch presents a result that has already been chosen, a split covered in our article on HTML5 slots. How the reel strips themselves are designed belongs to the slot development process.
Misreadings worth dropping
- "Pseudo means rigged." It means reproducible from a seed, not biased.
- "The generator runs hot and cold." A sound generator has no memory a player could feel; streaks are simply what randomness looks like.
- "Stopping the reels early changes the result." In typical online slots the outcome is fixed as soon as the spin starts.
How designers and testing labs check that a generator and a game behave as intended is the subject of our piece on Monte Carlo simulation, and the long-run figure they verify is explained in understanding RTP.
Knowing how the numbers are made does not tilt them in anyone's favour. Online games of chance are 18+ only, they cost money over time by design, and their legal status depends on where you live, so check the local rules before playing.