Lesson 47 of 51 · Advanced
Randomness with random
The random module adds unpredictability.
Python
from turtle import *
import random
bgcolor("black")
speed(0)
colors = ["cyan", "hotpink", "gold", "lime", "violet"]
for i in range(50):
color(random.choice(colors))
penup()
goto(random.randint(-200, 200), random.randint(-200, 200))
pendown()
circle(random.randint(10, 40))
done()Output

1
Random Functions
random.random() → 0 to 1. random.randint(a, b) → integer. random.choice(list).