R
Rishtaara
Python: Zero to Professional
Lesson 23 of 40Article14 min

Random & Requests Module Reference

random.randint, random.choice, random.shuffle, random.random for simulations and games.

Random module

random.randint, random.choice, random.shuffle, random.random for simulations and games.

Use secrets module for security (passwords, tokens) — not random.

Real-life example: random.choice is a lucky draw bowl — pick one winner from a list of names.

Random picks
import random

print(random.randint(1, 6))
print(random.choice(["apple", "banana", "mango"]))

Requests module

requests.get(url) fetches web pages and APIs. Check response.status_code and response.json().

Install: pip install requests. Always handle timeouts and errors.

Real-life example: requests is a postal worker — you give an address (URL), it brings back the reply.

GET request
import requests

resp = requests.get("https://api.github.com", timeout=5)
print(resp.status_code)
print(resp.headers.get("Content-Type"))