Dry run Fix Random Numbers

Slides:



Advertisements
Similar presentations
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Advertisements

4/16/2015 MATH 224 – Discrete Mathematics Counting Basic counting techniques are important in many aspects of computer science. For example, consider the.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Probability Predictions Ch. 1, Act. 5. Probability The study of random events. Random events are things that happen without predictability – e.g. the.
Math notebook, pencil, and possibly calculator. Definitions  An outcome is the result of a single trial of an experiment.  The sample space of an experiment.
Describing Probability
Probability theory and average-case complexity. Review of probability theory.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Section The Idea of Probability Statistics.
Bell Work: Factor x – 6x – Answer: (x – 8)(x + 2)
E Birbeck 7/04 Simple Probability Definition: Probability : the chance some event will happen. It is the ratio of the number of ways.
MOM! Phineas and Ferb are … Aims:
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
VOCABULARY CHECK Prerequisite Skills Copy and complete using a review word from the list: data, mean, median, range, outcome, probability of an event.
What is Probability?. The Mathematics of Chance How many possible outcomes are there with a single 6-sided die? What are your “chances” of rolling a 6?
1.4 Equally Likely Outcomes. The outcomes of a sample space are called equally likely if all of them have the same chance of occurrence. It is very difficult.
The Wonderful World… of Probability. When do we use Probability?
5.1 Probability in our Daily Lives.  Which of these list is a “random” list of results when flipping a fair coin 10 times?  A) T H T H T H T H T H 
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
Probability Bingo October 3, D Mathematics.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Experiments, Outcomes and Events. Experiment Describes a process that generates a set of data – Tossing of a Coin – Launching of a Missile and observing.
Probability Test Review (What are your chances of passing?)
Counting and Probability. Imagine tossing two coins and observing whether 0, 1, or 2 heads are obtained. Below are the results after 50 tosses Tossing.
3x + 2 6x3 - 5x2 – 12x – 4 2x2 – 3x – 2 6x3 + 4x2 -9x2 – 12x -9x2 – 6x
Adding Probabilities 12-5
CHAPTER 6 Random Variables
Probability Predictions Ch. 1, Act. 5.
Probability Fun For Grade 4, 5 and 6.
Chi Squared Test.
Probability Imagine tossing two coins and observing whether 0, 1, or 2 heads are obtained. It would be natural to guess that each of these events occurs.
4.5 – Finding Probability Using Tree Diagrams and Outcome Tables
Review Finish program Graphics Programming
Chapter 17 Thinking about Chance.
Stream Ciphers Day 18.
Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 Dice Project.
And and or…and RANDOMNESS
Computer Science 2 Getting an unknown # of …. Into an array.
Truth tables: Ways to organize results of Boolean expressions.
Repeat Day2 Dry Run Second Repeat Program
Probability.
COUNTING AND PROBABILITY
int [] scores = new int [10];
Computer Science 1 Warm-up: True/False Dry Run
Computer Science 2 Tally Arrays 2/4/2016.
What do you do when you don’t know how to get started.
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?
Computer Science II Second With files.
Computer Science 2 More Trees.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Warm-up: Dry Run DIV / MOD 2nd If Then Program
How can you make a guessing game?
Computer Science 1 Dice Project.
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
Understanding Code Workshop 2.
Exploring Computer Science Lesson 4-10 – Part 2
Computer Science I: Get out your notes.
Complete the sample space diagram on your whiteboards
Dry Run Fix it Write a program
Random Numbers while loop
int [] scores = new int [10];
Dry Run Fix it Write a program
Presentation transcript:

Dry run Fix Random Numbers Computer Science I: 10-4-2016 Dry run Fix Random Numbers

Learning Objectives Be able to dry run a program that uses a for loop. Get out your notes. Be able to dry run a program that uses a for loop. Be able to fix a program that uses a for loop. Be able to read a program that uses random numbers. Be able to write a program that uses random numbers.

DIV Pascal’s Integer Division How can you get an integer result when you divide? For example, if you divide 5 by 2 what do you think the answer would be? What about the remainder. Pascal has math operations for finding the result of integer division and the remainder of integer division.

DIV and MOD DIV is used to find the result of integer division For example X := 13 DIV 5; X:= 21 DIV 10; X:= 20 – 8 DIV 3; x:= 1 DIV 2; MOD is used to find the remainder of integer division X := 13 MOD 5; X:= 21 MOD 10; X:= 20 – 8 MOD 3; x:= 1 MOD 2;

DIV and MOD samples Ans:=23 DIV 10; Ans:= 14 DIV 4; Ans:= 52 DIV 5; Ans:= 23 MOD 10; Ans:= 14 MOD 4; Ans:= 52 MOD 5; Ans:= 14 MOD 3; Ans:= 8 MOD 9; Ans:= 5 MOD 10; Ans:= 4.13 MOD 2;

Dry Run the Following

This is fixyng.pas on the class website.

Random Numbers…why use them? Testing data Modeling Gaming Adding ‘chance’ to something

How do you do it? Seed the computer’s random number generator Randomize; {Command} Make the computer generate a random number in a given range. Random command Number:= random(12)+ 2;

Syntax Answer:= random(range) + offset; Coin:= random(2)+1; Die:= random(6)+1; Answer:= 2*random(range) + offset; Evans/Odds Evento100:= 2*random(50)+2; Oddto99:=2*random(50)+1

Example Program program flipper; var count, coin:integer; begin randomize; for count := 1 to 50 do coin:= random(2) + 1; {1 = heads, 2 = tails} if coin = 1 then writeln('Heads') else writeln('Tails'); end; {Of the for loop} end. {Of the program}

Reading code Name the range of values that the following could generate Ans:= random(5); Ans:= random(6)+2; Ans:= random(40)-7; Ans:= 2*random(10)+3; Ans:= 2*random(9)-7;

Writing code Write the random line to generate a number for the following ranges. 1-6 2-30 A pair of 6-sided dice 3-9 odd 12-24 even

Check for Understanding: Find the range of values the following code produces. 1) ans:=random(6)+1; 2) ans:=random(14)+2; 3) ans:=random(7)-4; 4) ans:=random(12)+5; 5) ans:=random(23)+8; 6) ans:=random(50)-5; 7) ans:=random(18)+370; 8) ans:=2* random(10) + 1; 9) ans:=2* random(9) + 6; 10) ans:=2* random(21) + 10; 11) ans:=2* random(100) + 51;

Check for Understanding: Write the line of code to generate the following ranges of values 8 to 24 even 7 to 35 odd -7 to 21 odd -10 to 10 even A pair of six sided dice

Program options If you are stuck… Hands on, Pseudo-code, Dry run, Flip a coin 100 times, show the total number of heads and tails AND which occurred the most often. Roll a pair of 6 sided dice 100 times. Find out which occurs most often, 3 or 11. Show how often each of these rolls occur and which occurs most often. Math tutor: User inputs the number of sample addition problems o show. The computer generates the problems and shows them to the user. The user guesses the answers At the end the computer shows how many the user answered correctly.