"
This article is part of in the series
Published: Sunday 27th November 2016

In Python, the random module allows you to generate random integers. It's often used when you need to a number to be picked at random or to pick a random element from a list. Using it is actually really straightforward. Let's say you want to print a random integer within a given range, like 1-100. Here's how you would write that code:

import random
print random.randint(1, 100)

The code above will return a random number from 0 to 100. To write the code, you just pass the range of numbers you want the random integer to be pulled from through the parentheses parameters. So if you want the range to be 1-100, the first parameter is 1, and the last parameter is 100 -- pretty simple!