Randint
random.randint is a Python standard-library function that returns a pseudorandom integer between specified inclusive lower and upper bounds.
Python Workout: 50 ten-minute exercises
randint is a function that returns a pseudo-random integer within an inclusive lower and upper bound.
- How it is used
- Generates a bounded random integer for interactive programs such as a number-guessing game.
- How deep it goes
- Explains importing random, passing two bounds, and remembering that the maximum is inclusive.
- Examples
- Uses a 0–100 guessing game and a random.randint(10, 30) assignment.
- What you can do after
- Build it from scratch by generating a bounded integer and using it in an interactive guessing loop.
Read how Python Workout: 50 ten-minute exercises explains randint →
Python Workout, Second Edition
random.randint is a Python standard-library function that returns a pseudorandom integer between two specified inclusive bounds.
- How it is used
- Generates an integer for interactive exercises such as a number-guessing game.
- How deep it goes
- Defines two-parameter invocation and inclusive bounds, then applies the result in a comparison loop.
- Examples
- Uses a 0-to-100 guessing game and a smaller random.randint(10, 30) assignment.
- What you can do after
- Build a guessing loop that generates a bounded integer, classifies guesses, and exits on an exact match.
Related concepts
- integerproduces · An integer is a whole number with no fractional part, including negative numbers, zero, and positive numbers.
- random modulepart of · The random module is a Python standard-library module that provides pseudorandom-value generation, selection, sampling, and related utilities.
- tensorproduces · A tensor is a multidimensional array-like numerical data structure whose elements are indexed along zero or more dimensions and support numerical computation.
- repetitionproduces · Repetition is the recurrence or repeated application of an action, operation, element, or pattern.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

