The random Module for Generating Random Data in Python


Generate random numbers, select random elements, and shuffle sequences.

Source Code

import random
print(random.randint(1, 100))  # Random integer between 1 and 100
print(random.choice(['red', 'green', 'blue']))  # Randomly select an element
numbers = [1, 2, 3, 4, 5]
random.shuffle(numbers)  # Shuffle a list
print(numbers)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments