Random Numbers Random numbers are extremely useful: especially for games, and also for calculating experimental probabilities. Formula for generating random.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
GCSE Computing Working with numbers. Challenge ‘Crimson Mystical Mages’ is a fantasy role playing board game. You need to create an electronic program.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Probability And Expected Value ————————————
CSE 115 Week 12 March 31 – April 4, Announcements March 31 – Exam 8 March 31 – Exam 8 April 6 – Last day to turn in Lab 7 for a max grade of 100%,
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
The If/Else Statement, Boolean Flags, and Menus Page 180
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
John Neal and Kalli Smith. Each player has a master number that starts at 10. The goal of the game is to get your opponent’s master number to 0. The first.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
The possible outcomes are 2 + 2, 2 + 3, 2 + 4, 3 + 2, 3 + 3, 3 + 4, 4 + 2, 4 + 3, The probability of an even sum is ____. The probability of an.
Brian Duddy.  Two players, X and Y, are playing a card game- goal is to find optimal strategy for X  X has red ace (A), black ace (A), and red two (2)
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
1 CSC 221: Computer Programming I Spring 2010 interaction & design  modular design: roulette game  constants, static fields  % operator, string equals.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Basic Functions. Excel can be a very powerful tool for displaying facts and figures, especially when you know how to make quick and easy use of its features.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Playing the Lottery 6/4/2016Copyright © 2010… REMTECH, inc … All Rights Reserved1 Probability Theory and the Lottery ● The Lottery picks numbers at random.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.
Two-Dimensional Arrays That’s 2-D Arrays Girls & Boys! One-Dimensional Arrays on Steroids!
Georgia Institute of Technology More on Creating Classes part 2 Barb Ericson Georgia Institute of Technology Oct 2005.
Chapter 4 Conditional Statements. A Programmer's Lament I really hate this damned machine; I wish that they would sell it It never does quite what I want.
WOULD YOU PLAY THIS GAME? Roll a dice, and win $1000 dollars if you roll a 6.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
The Monty Hall Simulation
6.5 Find Expected Value MM1D2d: Use expected value to predict outcomes. Unit 4: The Chance of Winning!
Binomial Probability Section Starter Here’s a game you will like: Let’s bet a dollar on this proposition: I will roll a fair die once. If.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
 Objective: In the game “Win to spin”, the winning player will be the one that accumulates the most of the points by spinning the spinner and hoping.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
int [] scores = new int [10];
Find Expected Value.  A collection of outcomes is partitioned into n events, no two of which have any outcomes in common. The probabilities of n events.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Boat Racing Game Challenge #3 By Chris Brown Under the direction of Professor Susan Rodger Duke University, January 2013 Based off of the Boat Racing Game.
Hangman Code Brittany Moses.
Boat Racing Game Challenge #4 By Chris Brown Under the direction of Professor Susan Rodger Duke University, January 2013 Based off of the Boat Racing Game.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
LESSON 3 Working with Functions, Formulas, and Charts.
FOP: While Loops.
Expected Value MM1D2 Students will use the basic laws of probabilities. d. Use expected value to predict outcomes.
While Loops in Python.
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Do While (condition is true) … Loop
Truth tables: Ways to organize results of Boolean expressions.
Truth tables: Ways to organize results of Boolean expressions.
See requirements for practice program on next slide.
CS2011 Introduction to Programming I Selections (I)
For First Place Most Times Up at the Table
Relational Expressions
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
WEEK 8 COURSE PROJECT PRESENTATION NAME: ALEXANDER WEISS CLASS: CIS115.
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
6.5 Find Expected Value MM1D2d.
Dry Run Fix it Write a program
While Loops in Python.
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Presentation transcript:

Random Numbers Random numbers are extremely useful: especially for games, and also for calculating experimental probabilities. Formula for generating random integers: (int)(Math.random()*(how many #s)+smallest)

examples Creates a random # between… x = (int)(Math.random()*6+1) // 1 to 6 y = (int)(Math.random()*7+50) // 50 to 56 z = (int)(Math.random()*21+100) // 100 to 120 Demo: RandomNumberDemo

A boolean variable is a variable that can only have 2 possible values: true or false – See demo: BooleanDemo A boolean expression means something very different – it is simply a segment of code that is either true or false, such as: (score > 90) (name.equals(“Peppers”)) (letter == ‘a’) So, essentially any expression you might see after if or while is a boolean expression

Assignments 1. Fifty Use a for loop to create and display 12 random #s between 1 and 50. Then display the following: – How many odd #s, how many evens – How many #s in the 30s – How many 37s – The average – The highest #, the lowest # – How many prime #s (your choice, you can do this the easy way [a bunch of ifs] or the challenging way: use a loop and a Boolean variable) – ***Make sure your results are correct.*** see next slide…

2) p. 185 # 15 – Think about it – how can you use random numbers to decide the computer’s “choice”? – Each round, make sure to display what the computer chose, as well as who won or lost (or if they tied). – The user should be able to play as many rounds as they like. 3)p. 185 # 16 – Add a betting feature, where the player begins with $500, and can bet money on each turn. They double their bet if 2 numbers match, they quintuple their bet if all 3 numbers match, they lose their bet if no numbers match.