liveBook · Manning

Randint

random.randint is a Python standard-library function that returns a pseudorandom integer between specified inclusive lower and upper bounds.

How 2 Manning books explain it

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.

Read how Python Workout, Second Edition explains randint →

Related concepts

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.