Students pick an item from a list at random with pick random 0 to length − 1, so every item can come up however long the list grows.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 7 min · Investigate 10 min · Modify 8 min · Mix it up 3 min · Make 8 min · Team picker 4 min
pick random (Math) gives a whole number between two numbers. length of array (Arrays) counts the items. A random item is get value at (pick random 0 to length − 1): the length is one more than the last place, because places start at 0. Using the length means new items are included without changing anything else.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Roll a real dice twice. Can it give the same number both times?
Roll a real dice twice to settle it: random has no memory.
Three cards numbered 0, 1 and 2 go in a hat. A student draws one, reads the item at that place, and puts it back.
Add two more items to the board but not to the hat: they never come up. That is Ana's bug.
Play rock, paper, scissors against the next pair: both shake at once.
Why it is length − 1. Ask them to count the places of a 3-item list aloud from 0.
| What you will see | A question to ask | The fix |
|---|---|---|
| One item never comes up. | Which places can pick random choose from? | Pick from 0 to length − 1, not from 1 and not a fixed number. |
| The minus block will not fit. | Is it the round number minus block from Math? | Drag Math's 0 − 0 block into the slot, then put length of array on its left and 1 on its right. |
| A number shows instead of the word. | Is the random number inside get value at? | pick random gives the place; get value at turns the place into the item. |
One possible solution for each task. Other correct programs are fine.

let answers = ["Yes", "No", "Maybe", "Ask again", "Never"]
input.onGesture(Gesture.Shake, function () {
basic.showString(answers[randint(0, answers.length - 1)])
})

let answers = ["Yes", "No", "Maybe", "Ask again", "Never"]
input.onGesture(Gesture.Shake, function () {
basic.showString(answers[randint(0, answers.length - 1)])
})
input.onButtonPressed(Button.A, function () {
basic.showNumber(answers.length)
})

let choices = ["Rock", "Paper", "Scissors"]
input.onGesture(Gesture.Shake, function () {
basic.showString(choices[randint(0, choices.length - 1)])
})
Open task: any program that does what the step asks.
Stretch: Make a dice: a list of six show leds pictures is hard to make, so use show number pick random 1 to 6 instead, and say why this one starts at 1.
Support: Give students the list and the on shake block with show string already in, and ask them only to build get value at with pick random.
A list has 6 items. What should pick random choose between, and why?
0 and 5 (0 to length − 1), because places start at 0, so the last of 6 items is at place 5.
Next: the final challenge, a pocket pet that uses everything in this course.