Python Random Module

The random module in Python provides functions that allow you to generate random numbers, select random elements from a list, and perform other randomization tasks. It's widely used in applications like simulations, games, and testing.

Commonly Used Functions

Example Usage

Python
import random

print(random.random())  # Random float between 0.0 and 1.0
print(random.randint(1, 10))  # Random integer between 1 and 10
print(random.choice(["apple", "banana", "cherry"]))  # Random element from list
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)  # Shuffle list in place
print(numbers)