A Pseudo-Random Number Generator (PRNG) is a mathematical equation that takes an initial integer (the Seed) and performs arithmetic manipulations to output numbers that appear completely unpredictable.
Notice how Seed A and Seed B produce entirely different sequences. But if you reset back to Seed A, every single number re-appears in the exact same sequence!
| Call # | Seed 42 | Seed 999 | Roll (1–6) |
|---|
Generating Random Numbers in Code
Random number generators are an essential tool in software development. In GCSE Computer Science, you need to understand how to generate pseudo-random numbers in both standard exam pseudocode and Python.
Standard Pseudocode
dice_roll ← random_int(1, 6)
// Generates float between 0.0 and 1.0
chance ← random()
Python 3 Implementation
# Generates integer between 1 and 6 inclusive
dice_roll = random.randint(1, 6)
# Setting an explicit seed for testing
random.seed(12345)
random.randint(a, b) is inclusive of both a and b. randint(1, 6) can return 1, 2, 3, 4, 5, or 6!
Real-World Application — Why Minecraft Uses Seeds
A Minecraft world is practically infinite (over 60 million blocks in diameter). If Mojang tried to store every block's coordinates and type on your hard drive, a single world would require hundreds of gigabytes of storage!
- Instead of saving billions of blocks, the game saves just ONE 64-bit number: the World Seed.
- When the player walks towards new chunks, mathematical noise algorithms evaluate the seed at those coordinates and generate mountains, caves, and ores in real-time.
- Two players on different computers who enter the same seed will explore the exact same world.
Cybersecurity & Cryptography — The Lava Lamp Wall
Because PRNG algorithms are deterministic, an attacker who discovers your seed can calculate every "random" encryption key you will ever generate! For encryption and banking security, computers require True Random Number Generators (TRNG) based on unpredictable physical phenomena:
Internet security giant Cloudflare films a wall of 100 bubbling lava lamps. Fluid turbulence and lighting photons create unpredictable physical noise to encrypt 10% of internet traffic.
Websites like Random.org use radio receivers tuned between stations to measure lightning storms and cosmic microwave background radiation.
Modern Intel/AMD chips contain hardware circuits that measure microscopic electrical thermal fluctuations in microscopic resistor junctions.