This tutorial is on how to create a random number generator in Python.
Before we begin, we first need to import the random module...
- import random
This allows us to use the random modules functions such as 'randrange' and 'randint'.
Random From Zero:
To get a random number from the beginning (zero/0), we can simply call the 'randrange' function from the random module and parse it a final/maximum value as an integer, like so...
The above code generates and outputs a random number between 0 and 100.
Or if we need to set a minimum value as well, we can use the 'randint' function. This function generates a random number between parameter 1 (minimum) and parameter 2 (maximum)...
- print(random.randint(20, 100))
The above code generates and outputs a random number between 20 and 100.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.