Random Numbers, Tuples, and Lists

Random Numbers

Randomly generated numbers are widely used in computation especially in simulations and security. An interesting video on random number generation: www.youtube.com/watch?v=1cUUfMeOijg


Random numbers are also useful in drawing unique patterns with turtle at each execution:

import turtle
import random

turtle.speed(9) 
turtle.pensize(5)  

for i in range(100):
    radius = random.randint(20, 200)
    turtle.circle(radius)

turtle.done()

We can further improve the code to draw in the lower part of the x axis:

import turtle
import random

turtle.speed(9) 
turtle.pensize(5)  

for i in range(100):
    radius = random.randint(20, 200)
    turtle.circle(random.choice([-1,1]) * radius)

turtle.done()

import random is necessary for accessing the random library of Python.