The module named random can be used to generate random numbers in Python. To use a module you need to type import module. This loads all of the functions inside the module.
Keep in mind that random numbers with the random module are pseudo-random numbers. For most programs this is fine.
Related course: Complete Python Bootcamp: Go from zero to hero in Python
To create random numbers with Python code you can use the random module. To use it, simply type:
This module has several functions, the most important one is just named random().
Type the program shown below and run it:
Try the exercises below
- Make a program that creates a random number and stores it into x.
- Make a program that prints 3 random numbers.
After completing these continue with the next exercise.