Python randint function

Parbati Budhathoki
1 min readApr 22, 2020

--

The random module provides access to functions supporting multiple operations. The most significant thing maybe is that it helps you to produce random numbers. For example, if we want the machine to pick a random number in a given range, pick a random element from a list, pick a random card from a deck, and so on.

image source: https://www.onlinegambling24.com/understanding-how-the-random-number-generator-works/

randint () is an inbuilt function of the random module in python3.

Syntax:

randint(start, end)

Parameters: start and end values must be of integer type

Returns:

A random integer within the given range as parameters.

Errors and Exceptions:

ValueError: Returns a ValueError when floating-point values are passed as parameters.

TypeError: Returns a TypeError when anything other than numeric value is passed as parameters.

→ if we wanted a random integer, we can use the randint function

Randint accepts two parameters: the lowest and the highest number.

Generate integers between 1,10. The first value should be less than the second.

--

--