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.
Also covered in
- Learn AI-Assisted Python Programming, Second Edition
- Tiny Python Projects: Learn coding and testing with puzzles and games
- Evolutionary Deep Learning: Genetic algorithms and neural networks
What to know first
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
Related concepts
- integerproduces · An integer is a whole-number mathematical value, including negative numbers, zero, and positive numbers, with no fractional part.
- 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 numerical array whose values are arranged along indexed dimensions and can be manipulated through mathematical computation.
- repetitionproduces · Repetition is the recurrence or repeated application of an action, operation, element, or pattern.
Questions about randint
What is randint?
random.randint is a Python standard-library function that returns a pseudorandom integer between specified inclusive lower and upper bounds.
Which Manning books explain randint?
Python Workout: 50 ten-minute exercises and Python Workout, Second Edition.
What should I know before learning randint?
Manning books that teach randint usually introduce Python first.
What is the difference between randint and random.shuffle?
random.randint is a Python standard-library function that returns a pseudorandom integer between specified inclusive lower and upper bounds. random.shuffle is a Python standard-library function that randomly reorders the elements of a mutable sequence in place.
What is randint part of?
Randint is part of random module. The random module is a Python standard-library module that provides pseudorandom-value generation, selection, sampling, and related utilities.
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.

