The
randint()
function in the random module generates a random integer within a specified range.
randint(start, stop)
copy
The two parameters; start
and stop
represent the lower and an upper bound (inclusive of both) of the range. Both parameters should be strictly integers.
start |
Required. Represents the start of the range of the number to be generated |
stop |
Required. Specifies the end of the range of the number to be generated |
This function returns a random integer in the range specified by the start and stop parameters.
The function is useful for generating random numbers for simulations, games, or any other application where random numbers are needed. It is also useful for data analysis and machine learning tasks where we need data samples drawn from a certain range of numbers.
Generate a list of random integers using randint()
We can append the generated integers to a list so as to get a list of random integers.