Programs can generate random numbers — numbers that cannot be predicted in advance. This is essential for games, simulations, testing, and security applications.
Computers use pseudo-random number generators (PRNGs) — algorithms that produce sequences of numbers that appear random but are actually deterministic (determined by a starting value called the seed).
In AQA pseudo-code, the function to generate a random integer is:
| Application | How RANDOM() is used |
|---|---|
| Dice / card games | RANDOM(1,6) for a dice; RANDOM(1,52) for a card |
| Simulations | Modelling probability, traffic flow, weather |
| Test data generation | Creating random inputs to test programs |
| Shuffling | Randomly reordering array elements |
| Password generation | Selecting random characters from a character set |
| Cryptography | Generating random keys (requires true randomness) |
Pseudo-random numbers (PRNGs) use a mathematical algorithm. They are predictable if you know the seed — the same seed always produces the same sequence.
True random numbers are unpredictable — generated from physical processes (mouse movements, radioactive decay). These are required for cryptography.
| Pseudo-random | True random | |
|---|---|---|
| Source | Algorithm + seed | Physical process |
| Predictable? | Yes (with same seed) | No |
| Speed | Fast | Slower |
| Use case | Games, simulations | Encryption keys |
8 questions · 20 marks
| Term | Definition |
|---|
Timed exam conditions.