Quickly generate random numbers in Python 3
A quick guide on how to generate random numbers using various methods included in the random module.
The quick example below will generate a number between 0.0 and 1:
import random r1 = random.random() print(r1)
We can specify other criteria for generating the number:
# Generate a number between 0 and 1 random.random() # Select a random choice from a list random.choice([1,2,3,4,5]) # Select a random number from within a range of numbers random.randint(1, 1000)
There are many more additional features of the random module, see here for more information.