random Module
noun
say it: “RAN-dum MOJ-ool” /ˈrændəm ˈmɒdʒuːl/
A module in Python's standard library that picks random numbers and random items, used for games, quizzes, samples and shuffling.
What is the random module?
The random module picks random numbers and random items, handy for games, quizzes and shuffling.
import random
prizes = ["mug", "t-shirt", "sticker"]
print(random.choice(prizes)) # e.g. sticker
print(random.randint(1, 100)) # e.g. 42
In a sentence
- “The prize wheel uses the random module to choose a winner.”
- “random.shuffle() from the random module mixed up the quiz questions.”
Level: Apprentice · More Python terms at this level
Updated