Random Numbers
Deprecated Lab — Trinket is shutting down
This lab was written for Trinket.io, which is shutting down in August 2026. The embedded trinket.io links on this page will stop working after that date.
These pages are kept for reference only. The current version of this course now runs every lab as an inline Skulpt editor right in the page — no account or install needed. Start at Chapter 1: Welcome to Python.
Random Circles¶
In this exercise we will draw 10 random circles on the screen. We will use the random function randint(min, max) that will generate a random number between the minimum and maximum values. Since we are drawing on a grid that goes from -200 to 200 here is the random function:
1 | |
Sample Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Drawing¶

Run the Example on Trinket¶
Run the Random Example on Trinket
Experiments¶
- Can you create a variable that is used to control the distance from the origin to wander? Right now the distance is set to be 200 on each extent.
- Can you create a variable for the number of circles to draw?
- Go to the Trinket colors page and see the name of other colors you can use. Note that you can use any of these colors in your lists.
- Right now, all the circles are 7 pixels in size. Can you make the circles have a random size from 3 to 20?