PRNG

PRNG

A PRNG (pseudorandom number generator) is an algorithm that computes a long sequence of numbers from a single starting value — numbers that appear random but aren't. PRNGs are embedded in nearly every piece of software that needs randomness – from computer games to simulations to AI models.

A PRNG – short for pseudorandom number generator – is an algorithm, meaning a computational procedure, that produces numbers which look like randomness. The word “pseudo” is crucial here: the numbers are not truly random. They follow a fixed mathematical rule. Anyone who knows the starting value can recalculate the entire sequence of numbers exactly. That sounds like a drawback – but in many applications it’s precisely the strength of the method. True randomness, after all, is hard to generate and even harder to reproduce.

Why pseudorandomness is so useful

Many programs need random numbers in huge quantities and very quickly. A computer simulation modeling the weather or the stock market may require millions of random values per second. Genuine physical randomness – for instance, from noise picked up by a microphone – simply cannot be generated at that scale. A PRNG delivers the numbers instantly, because it only computes.

Reproducibility is especially important. When training an AI model, randomness determines how data is shuffled or how weights – the model’s internal adjustable values – are initially set. If a researcher wants to repeat their experiment, they must use the same randomness. With a PRNG, this is possible: you simply store the starting value, known as the seed, and get the same sequence every time. True randomness cannot provide that.

From seed to number sequence

Every PRNG starts with a seed – a single number that serves as the starting point. It applies a mathematical function to this seed and generates a new number. This new number becomes the input for the next step, and so on. The resulting sequence can be billions of numbers long before it repeats. A widely used algorithm called the Mersenne Twister, built into Python and many other programming languages, produces a period of 2¹⁹⁹³⁷ − 1 numbers – a number with more than 6,000 digits.

Computer scientists measure quality by how well the sequence passes statistical tests: Do all numbers occur evenly? Are there no hidden patterns? A poor PRNG produces sequences that seem random at first glance but, for example, always alternate between even and odd numbers. For many applications, this is a fatal flaw. For cryptographic purposes – such as encrypting messages – an ordinary PRNG is not sufficient anyway. Those use cases require specially secured variants, so-called CSPRNGs.

The seed itself has to come from somewhere. Software often uses the current time, the user’s mouse movement, or noise values from the operating system for this purpose. The seed is the only point at which genuine randomness enters the system – everything after that is pure computation.

PRNGs in AI, games, and security

In everyday life, you encounter PRNGs constantly, usually without noticing. In computer games, they determine which items a defeated enemy drops, how landscapes are generated, or how AI opponents behave. The game Minecraft, for example, builds its entire world from a single seed – which is why players can share worlds simply by passing along a number.

In AI development, the term appears in almost every training script. Frameworks like PyTorch or TensorFlow allow you to manually set the seed so that experiments remain comparable. In scientific publications, the seed used is therefore often reported – much like a chemist notes the temperature of their experiment.

In IT security, by contrast, the PRNG marks a vulnerability if used incorrectly. In 2008, it was discovered that a widely used Linux version restricted the seed for secure keys to only a few possible values. Attackers could try out all the possibilities and thereby crack connections that were supposed to be encrypted. The incident shows: the quality of randomness directly determines the security of a system.

Latest News

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.