Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro CS – Probability and Random Numbers

Similar presentations


Presentation on theme: "Intro CS – Probability and Random Numbers"— Presentation transcript:

1 Intro CS – Probability and Random Numbers
Lesson Plan 6a

2 Goals Students can explain random numbers and how computers can generate them Students can generate random numbers Students can use the computer to simulate random number experiments to observe probability statistics Students can predict probability statistics for a given problem Students can express probability as ratios, decimals, and percentages Students can write code to generate probability statistics as ratios, decimals, and percentages

3 Objectives Students are introduced to random number generation by computers and how they can be used to simulate chance Students are given real probability problems to code and solve Results are demonstrated through predications, demos of running code, and displayed results

4 Pre Requisites Knowledge of IF blocks, Loops (to simulate mutiple trials), variables (to capture results) Basic Understanding of BYOB

5 Materials Slides with examples (or present on whiteboard)
PCs with Chrome browser to access Snap web site

6 Lesson Description Students learn about random number generation in computers, and how it can be used simulate probability experiments Students practice and extend examples Students solve probability problems using code and the computer Students analyze their and others’ solutions, and collaborate towards shared solutions

7 Lesson Procedure Warm-up: Define/research what probability is, with an example. Research an example of how random numbers are used with computers to simulate chance Quick review of IF block, Variables, and Loops Introduce PICK RANDOM through student investigation and observation of sample work Give exercises for in class practice Walk the room answering questions, looking over the shoulder, asking questions, etc. Check off solutions for completeness and accuracy Review

8 Closure/Conclusion Summary
Random numbers are a powerful way to simulate real world problems and introduce random behaviors into normally predictable code Future thinking: Discuss Monte Carlo simulations as they relate to Finance, Airplane Boarding Optimization, Sporting Event Results Ask questions on what is confusing or needs more time/practice

9 Random Numbers Lesson 5

10 Warm-up Research/define probability, with a real-life example
Research another example of how computers are used to simulate chance

11 Review: IF blocks What are IF Blocks?
IF blocks are used to help make decisions and branch your code. When the IF Block statement is true, whatever is contained inside the decision block is done Other blocks that use logic: IF/ELSE, Repeat Until, Wait Until Can anyone tell me what they think an IF block will do? What do you think this sequence will do? Note: Here a double inquiry about “if on edge” happens. The block used can be applied even without the decision-block. But for gaining understanding of the concept decision this way works better.

12 Review: Variables Variables are places we can store results/values
Variables can be changed any time Variables can be incremented by one to count things

13 Review: Loops Used to repeat things a few to many, many times
Can repeat: Forever (FOREVER block) A specific number of times (REPEAT 10 block) Until a test is True (REPEAT UNTIL <test> block)

14 Generating Random Numbers
Usually, computers are very predictable 3+5 will also equal 8 for a computer Spell checking, etc. Sometimes we want computers to simulate life by being less predictable We can use Random Numbers to: Simulate chance (rolling dice, unpredictable events, etc.) Track results in variables Run thousands/millions of simulations very fast We use the Pick Random block (on the green tab)

15 Investigation Pair up. If you get stuck, ask another pair.
Simulate the following by having a sprite Say: the result of rolling one six-sided die the result of rolling two, three, four, or five six-sided dice the result of rolling one ten-sided die the result of picking a random card from a deck sprite must say "Ace of Clubs", "6 of Hearts", etc. Hint: use Join block on green tab to put words/numbers together, and IF blocks

16 When to use Pick random When you want to simulate chance:
50/50 99/1 When you want to wait a random amount of time Wait (pick random 6 to 10) When you want to pick a random thing from a list of things Picking a word in Hangman (future project in class) When you want to make game behavior unpredictable Sometimes go left, sometimes right, etc.

17 Coding problem Write the following programs:
Computer rolls 2 dice, calculate the probability of each roll (2-12) Use the computer to roll 5 dice to play Yahtzee Roll dice, pick all/some/none to keep, repeat 3 times Mark (on paper, or write code), to track which scores to take after 3 roles Repeat until you can't play, or all categories filled

18 Review You’ve just learned the basics of random numbers and using computers to measure probability Simulate chance Experiment to calculate results Future thinking: Monte Carlo calculations Finance: predict retirement outcomes Sports: predict team scores Airplane boarding optimization: predict and test models


Download ppt "Intro CS – Probability and Random Numbers"

Similar presentations


Ads by Google