Learn Alice in FREE step-by-step lessons.
Module 16: Random Numbers
In this module you will learn more about random variables.
We can use random numbers in many ways.
One thing we can do with random users is to flip a coin or select a card from a deck. Those are things that we think of as random.
We can also use random numbers to make movement seem more natural.
When a person jumps up and down, they don't jump exactly the same amount each time, so we could have them jump a random amount within a range.
Goals:
- Learn to use random numbers
- Understand how random numbers make it possible to create games
- Understand how random numbers make the movements of the characters more natural
Objectives:
- Write code to generate random numbers in 2 different ways.
- Use random values in your animation procedures so that characters move more naturally.
(For example, a fish swimming back and forth doesn't move exactly the same amount each time.) - Use loops to create a number guessing game with hints \"too high\" and \"too low\"
Please study the material at each of the links below.
Displaying some random values: Uses textModel to display a random double value between 0 and 1.
Displaying values from 1 to 6: A random integer from 1 to 6 inclusive to roll die
Panda Turns a Random Amount: A random double
A Counting Quiz: How many fish do you see? (Some of the fish are invisible.)- Addition Quiz: Bears ask you to add numbers, then tells how many you got right.
- Guess the Aliens number: Loops until the user guesses the number: give hints "too high" and "too low"
A Penguin Jumps Up and Down: Use a random value each time he jumps to make it look more realistic.
A Fish swims back and forth: Random numbers for the distance to swim makes it more realistic.
Self Study Questions: What have you learned?
Discussion questions: What do you think?
Glossary for random lesson
Full Glossary