In order to use this library, we must import it first. For this purpose, you must add the following line to the beginning of your program:
import random
Now we can use the commands in this library!
In order to generate a random number, we can use the random.randint() command. This command has two input parameters:
-
The smallest number it can select;
-
The largest number it can select.
Here's an example where we write a random number between 0 and 10 in a variable named "secret_number":
secret_number = random.randint(0, 10)
If you wish to learn more about how these random numbers are generated, you can follow this link. There you will find a detailed explanation on how the random library works.