Python Int – Generating a random number

Here we will be creating a script in Python that will generate a random number within a given range. To do this we will be using the random module which enables us to a random number generator.

We begin by importing the module and make use of the ‘randint’ function which will return a random integer within our given range of 1-100.

import random
print(random.randint(1, 100)) 

If you are wanting to increase the range or even have a more selective range, you would change the code as appropriate.

For example, a random number between 650 and 820.

import random
print(random.randint(650, 820)) 

Leave a Reply