---
title: "random.randint"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/random/randint"
updated: "2026-10-05"
---

Picks a random whole number between two numbers.

## Synopsis

```python
import random
random.randint(a, b)
```

## Description

Both ends are included: `randint(1, 6)` can give 1, 6, or anything between. That is different from `range`, which stops before its end.

## Parameters

| Name | Meaning |
| --- | --- |
| `a` | The smallest number allowed. |
| `b` | The largest number allowed. |

## Return value

An `int`.

## Example

```python
import random

for i in range(5):
    print(random.randint(1, 6))
```

It prints something like this. Your values will differ: they are random.

```text
5
4
3
3
3
```

## Common mistake

```python
import random

print(random.randint(6, 1))
```

Python stops with:

```text
ValueError: empty range in randrange(6, 2)
```

`a` must not be bigger than `b`. Write the smaller number first.

## See also

[random.choice](/student-handbook/python-manual/random/choice), [range](/student-handbook/python-manual/built-in-functions/range)

[random.randint in the Python documentation](https://docs.python.org/3/library/random.html#random.randint)
