Python Random Module Guide
Python Random Module Guide
The `random` module in Python provides functions for generating random numbers and performing random
operations.
1. random.random()
Example:
import random
2. random.uniform(a, b)
Example:
3. random.randint(a, b)
Example:
Example:
5. random.choice(sequence)
Example:
Example:
7. random.sample(population, k)
Example:
8. random.shuffle(x)
Example:
x = [1, 2, 3, 4]
random.shuffle(x)
9. random.seed(a=None)
Example:
random.seed(42)
Example:
state = random.getstate()
print(random.random())
random.setstate(state)
Usage Note:
- Use `random.sample()` if you need unique values, otherwise use `random.choices()` for random selections
with replacement.