Random Numbers

Random numbers are incredibly useful to programmers. They allows us to add variation to our programs to make them more interesting.

Every video game makes use of random numbers to make different actions less predictable:

  • Shooting a weapon in a FPS will be impacted by random numbers to perhaps make the weapon jam, or impact how accurate your shot it
  • Any action or attack in an RPG game will be influenced by random numbers to determine how much damage is dealt

Random numbers are also essential to security and keeping our data safe through encryption.

How "random" are random numbers?

Random numbers are actually really hard for computers to generate, most the numbers we get from them aren’t actually random, and rely on measurable quantities the computer can access such as time, mouse movement, keyboard key presses. We often refer to random numbers that computers generate as pseudo-random - this is because with enough knowledge of a system that generates the number it would be possible to predict it.

To generate true random numbers we have to get creative. The internet company Cloudflare generates random numbers for use in encryption by taking regular photographs of 100 lava lamps. The real world is full of systems which can generate random and chaotic numbers which cannot be predicted.


Included in the following specifications:
KS3 Computing