GCSE Computer Science (Pearson IGCSE)

Topic Summaries

ALGORITHMS AND PROGRAMMING: Programming techniques

Random number generation (RNG)

  • RNG can be used to add unpredictability in programs which is useful for things like games and simulations.
  • You must import the random module to use this.

import random

number = random.randint(1, 100)

# Random no. between 1 and 100

 
 

dice = random.randint(1, 6)

print(dice) # Random no. between 1 and 6

Unlock Random number generation (RNG)

Sign up to unlock the rest of this topic — plus every other topic, video, flashcard set and eBook guide in your SnapRevise Digital subscription.

Cancel anytime — instant access the moment you sign up.