Randomization
Time 2 hrs

Difficulty Beginner
Prerequisites Variables
Departments Science
Authors Sandra Kuipers
Groupings Individual
Pairs
Threes
Minimum Year Group None

Randomization!

### Outline

 Learner OutcomesStudents will: ... Competency Focus ... Interdisciplinary Connections ... ReflectionWhat was successful? What needs changing? Alternative Assessments and Lesson Ideas? What other Differentiation Ideas/Plans could be used? ... CreditsAny CC attribution, thanks, credit, etc. Thumbnail Image by ejaugsburg from Pixabay

This page requires you to be logged in to access it. Please login and try again.
5 mins
What is randomization?
The Pitch
• Where do random numbers come from?
• In real life, we might roll a dice to get a random number.
• There isn't a tiny dice inside your computer ... is there?

• So-far, we've learned that all data is stored as 1s and 0s.
• So how does a computer come up with a number that is random?
• And, how can we use these random numbers in our code?
10 mins
Creating Random Numbers
Theory

• Your computer doesn't have a tiny dice inside of it .... does it?
• The answer is: kind of, yes.
• Every computer has a clock inside it.
• Computers can perform operations at a scale of a billionth of a second.
• So, the clock inside your computer keeps track of time on a very small scale.
• Often, when we ask the computer for a random number, it grabs a random digit from the current time. Then, it runs that number through an algorithm to mix it up a bit.
• But that really isn't random ... right?
• These kinds of numbers are not "true" random numbers.
• But usually, they're random enough for our games and apps.
10 mins
Using Random Numbers
Digging In
• Random numbers power our video games, help us create new music, and other awesome things.
• How can we use random numbers in our code?

var myRandomNumber = random(100);

if (myRandomNumber > 50) {
// Do something!
} else {
// Do something different?
}
• The random() function generates a number between 0 and the number we pass into it.
• Similar to a dice roll, we can use a random number along with conditionals to make decisions.
15 mins
Randomness is Useful
Digging In
"Randomness can be quite useful for a computer program. If you were playing a game, for example, you probably wouldn't want it to be exactly the same every time, so you could use random numbers for things like starting position, speed and angle. You might want to simulate a die roll or a coin toss, or you might want to quickly generate lots of data to test your program."

Check out

The Need for Random Numbers

which has several great uses for randomization.

10 mins
The Difficulty in Randomness
Theory
• It's easy to generate pseudorandom numbers.
• We just take some "random" bits, like the time in microseconds, and run them through an algorithm to mix them up a bit.
• These kinds of random numbers work fine for video games and apps.
• But what about computer security and cryptography?
• Pseudorandom numbers aren't secure enough!
• So ... what is a random number and why is it so difficult to generate them?

10 mins
More Than Numbers
Theory
• Random numbers are just the tip of the iceberg!
• We can use randomness to generate images, sounds, video game levels.

60 mins
Design a Jack-o-lantern
Evidence
• Can you design a Jack-o-lantern that is randomly generated?

• Draw a pumpkin using the p5js editor (be sure to save your sketch as you go!)
• Then use random number generation to randomly determine the eyes, mouth and other features.
• Can you add a button that randomizes the jack-o-lantern every time it's clicked?
• Can you think of other ways to randomize your jack-o-lantern?
• Feel free to add a background and a scene around the jack-o-lantern.
• Once your creation is complete, share a link to your sketch as evidence of your learning in this unit.

## Embeds

There are no records to display.