Random numbers

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

Random module

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:

Study drill

Try the exercises below

After completing these continue with the next exercise.

Answers

Previous
Next

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">