0% found this document useful (0 votes)
226 views

Random Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views

Random Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

The random module in Python provides functions to generate random numbers, sequences,

and perform random selections. It's a part of Python's standard library and offers various
methods for randomness-related tasks. Here's an overview of commonly used functions in the
random module:
Generating Random Numbers:
1. random(): Returns a random float between 0 and 1.
import random
num = random.random()

randint(a, b): Returns a random integer between a and b (inclusive).


num = random.randint(1, 100)

randrange(start, stop, step): Returns a randomly selected element from the specified range.
num = random.randrange(1, 101, 2) # Random odd number between 1 and 100

uniform(a, b): Returns a random float between a and b.


num = random.uniform(1.0, 10.0)

You might also like