# Python Random Module

The `random` module implements pseudo-random number generators for various distributions.

> **Warning:** The pseudo-random generators of this module should not be used for security purposes. For security or cryptographic uses, see the [[programming/python/modules/secrets-module|secrets]] module.

## Importing the Module

```python
import random
```

## Random Integers

```python
# Random integer between a and b (inclusive)
print(random.randint(1, 10))

# Random integer from range(start, stop, step)
print(random.randrange(0, 101, 2)) # Even number between 0 and 100
```

## Random Floats

```python
# Random float between 0.0 and 1.0
print(random.random())

# Random float between a and b
print(random.uniform(1.5, 10.5))
```

## Sequence Operations

### Choice

Pick a random element from a non-empty sequence.

```python
items = ['apple', 'banana', 'cherry']
print(random.choice(items))
```

### Shuffle

Shuffle a sequence in place.

```python
deck = [1, 2, 3, 4, 5]
random.shuffle(deck)
print(deck)
```

### Sample

Return a k length list of unique elements chosen from the population.

```python
print(random.sample(range(100), 5))
```

## Seeding

Initialize the random number generator. Useful for reproducibility.

```python
random.seed(42)
print(random.random()) # Will always print the same number for this seed
```

[[programming/python/python]]