Random library

The code below demonstrates how a library (like random) can be imported and then used.

random is a Python "module". It provides functionality associated with randomness / probability.

import random as rd
# Call the FUNCTION named random 3 times and assign the result of each
# call to a variable.
a = rd.random()
b = rd.random()
c = rd.random()
print("a is", a)
print("b is", b)
print("c is", c)

# random isn't the only function in the random module.
# Do a google search for "python random library" or 
# go here: https://docs.python.org/3/library/random.html
# to learn more.

print("Now keep pressing Ctrl+Enter to run this cell many times!")
print("Notice how the values of a,b, and c keep changing!")
a is 0.4969263088042536
b is 0.3784298209627044
c is 0.5713035042669655
Now keep pressing Ctrl+Enter to run this cell many times!
Notice how the values of a,b, and c keep changing!

Last updated