KnowledgeBoat Logo
|

Computer Science

Out of random() and randint(), which function should we use to generate random numbers between 1 and 5. Justify.

Python Modules

1 Like

Answer

To generate random numbers between 1 and 5, we should use the randint() function from the random module. The randint(a, b) function accepts two parameters, a and b, as the lowest and highest number, returns a number N in the inclusive range [a, b], which signifies a <= N <= b. This function generates a random integer number between two given numbers. In contrast, the random() function generates a random floating point number from 0 to 1.

Answered By

3 Likes


Related Questions