Short answer
A computer cannot generate truly random numbers on its own because it is a deterministic machine — given the same inputs, it always produces the same outputs. Instead, it uses a pseudorandom number generator (PRNG): an algorithm that produces a sequence of numbers that appears random but is actually calculated from a starting value called a seed.
At a glance
- Key stage
- GCSE
- Subject
- Computing
- Type
- Explainer
- For
- Students
- Read time
- 5 min
- Last updated
- 8 October 2026
Where this fits
- Key Stage 3Years 7–9
- GCSEYears 10–11This article
What is a seed and why does it matter?
The seed is the input value that starts the PRNG algorithm. Starting from the same seed always produces exactly the same sequence of numbers. This is both the strength and the limitation of PRNGs:
- Strength — a program that sets a known seed produces reproducible results, which is essential for debugging, scientific simulations, and games where a level must regenerate identically.
- Limitation — if an attacker knows the seed, they can reproduce the entire sequence and predict future "random" values.
In Python, random.seed(42) fixes the seed. Calling random.randint(1, 100) after that will always give the same sequence. Without a seed call, Python uses the current system time in nanoseconds as the seed — different every run, so the output appears random.
What is a linear congruential generator?
The linear congruential generator (LCG) is one of the simplest and most studied PRNG algorithms. It produces each new value using the formula:
X(n+1) = (a × X(n) + c) mod m
Where:
X(n)is the current value (starting with the seedX(0)).ais the multiplier.cis the increment.mis the modulus (determines the maximum value).
Worked example with a = 5, c = 3, m = 16, seed X(0) = 1:
| Step | Calculation | X(n) |
|---|---|---|
| n=0 | (seed) | 1 |
| n=1 | (5 × 1 + 3) mod 16 | 8 |
| n=2 | (5 × 8 + 3) mod 16 | 11 |
| n=3 | (5 × 11 + 3) mod 16 | 10 |
| n=4 | (5 × 10 + 3) mod 16 | 5 |
| n=5 | (5 × 5 + 3) mod 16 | 12 |
The sequence 1, 8, 11, 10, 5, 12, … looks reasonably random but will eventually cycle (repeat). The period of an LCG — how many values it generates before repeating — depends critically on the choice of a, c, and m. Poor choices produce short periods and visible patterns.
What is the difference between pseudorandom and truly random numbers?
| Property | Pseudorandom (PRNG) | Truly random (TRNG) |
|---|---|---|
| Source | Mathematical formula | Physical process (noise, radioactive decay) |
| Reproducible with seed? | Yes | No |
| Predictable if seed known? | Yes | No |
| Speed | Very fast | Slow (depends on physical events) |
| Suitable for gaming/simulations | Yes | Overkill — slower with no benefit |
| Suitable for cryptography | Only if cryptographically secure (CSPRNG) | Yes |
Most computers gather genuine randomness from hardware events — mouse movements, keyboard timing, network packet timing — and mix this into a pool to periodically re-seed PRNGs, giving a practical mix of both worlds.
What are cryptographically secure PRNGs?
A standard PRNG such as Python's random module is not suitable for cryptography. Given enough output values, a clever attacker can reverse-engineer the state and predict future values — which would allow them to forge session tokens or break encryption.
A cryptographically secure PRNG (CSPRNG) is designed to resist this: even knowing large amounts of output, an attacker cannot determine the internal state or predict future values. Python's secrets module uses the operating system's CSPRNG (e.g. /dev/urandom on Linux). It is used for:
- Generating secure passwords and API keys.
- Session tokens for web authentication.
- Nonces in cryptographic protocols.
The key rule: use random for games, simulations, and data shuffling; use secrets for anything security-related.
Where are random numbers used in computing?
- Games — map generation (Minecraft's worlds are seeded procedurally), loot drops, enemy behaviour.
- Simulations — Monte Carlo methods use thousands of random samples to approximate answers to complex probability problems (e.g. predicting weather, pricing financial options).
- Testing — generating test data that covers many possible inputs.
- Cryptography — generating keys, nonces, and session IDs (requires CSPRNG).
- Sampling — choosing a random subset of data for statistical analysis.
- Load balancing — randomly distributing requests across servers.
Frequently asked questions
Why does Python's random module give the same numbers when I use the same seed?
Because random is a PRNG — it is deterministic. The seed fully determines every subsequent value. This is useful: set random.seed(0) at the start of a test and your test always runs with the same "random" data, making bugs reproducible. Reset the seed with random.seed() (no argument) to restore unpredictable behaviour.
Can you make a computer generate truly random numbers?
Yes, but it requires measuring a physical process. Modern processors include hardware random number generators (HRNGs) that measure thermal noise in transistors — quantum-mechanical fluctuations that are genuinely unpredictable. Operating systems mix this entropy with PRNG output. You can access true randomness in Python via os.urandom() or the secrets module, both of which draw from the OS's entropy pool.
Why does the period of an LCG matter?
If an LCG's period is shorter than the number of random values your program needs, the sequence will repeat — introducing detectable patterns. For simple games this is usually fine (a period of millions is more than enough). For statistical simulations and security applications, the period must be astronomically large. Modern PRNGs like the Mersenne Twister (used by Python's random) have a period of 2¹⁹⁹³⁷ − 1, effectively infinite for practical purposes.
Is Minecraft's world generation random or pseudorandom?
Pseudorandom. Every Minecraft world is generated from a seed — a number you can share with friends so they get the exact same world. When you choose "Random Seed", the game uses the system clock to pick a seed, making it appear random. But the terrain, villages, and biomes are fully deterministic given that seed. This is why speedrunners can search for "seed-hunted" worlds with the most favourable features.
Want to explore how randomness works in programming, simulations, and cryptography? Professor Turing at aitutors.me can set you challenges at exactly your level.
Key terms
- pseudorandom number generator (PRNG)
- seed
- Strength
- Limitation
- linear congruential generator (LCG)
- period
- Games
- Simulations