13.03
Completed
Using Random in Python Using Random in Python

Use Python's random module to roll numbers, pick list items, and build tiny games and generators.

Using Random in Python

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

Using Random in Python

Give your Python programs a little unpredictability. This Block introduces the standard-library random module through practical examples: rolling numbers with random.randint(), selecting list items with random.choice(), and combining random results into tiny games and generators.

What you will learn:

  • Import and use Python's random module
  • Generate whole numbers with random.randint() and understand inclusive ranges
  • Select one item from a non-empty list with random.choice()
  • Use random results inside functions, comparisons, games, and simple generators
  • Recognize common mistakes and understand why random is not suitable for security-sensitive values

By the end, you will be ready to add simple, unpredictable behavior to your own Python programs while keeping the surrounding code clear and familiar.

> Start now 64 cards · about 8 min

Ready to practice this in the browser?

> Play now