The goal of this lesson is to learn to use random numbers.
Random numbers make it possible to create games and to make the movements of the characters more natural.
In this nodule 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.
In order to do this you will:
- 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"
Print the lesson
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
- 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 swhim makes it more realistic.
- Self Study Questions
- Discussion Questions
Active LearningCreate a soccer match
Like us on Facebook:
OER: Open Educational Resource
Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 17 2017 16:46:49.