Random Numbers. Are a series of numbers that have no pattern to them Ex) 7, 31, 4, 9, 8, 99… Random Numbers are used in… - Computer Games - Lotteries(6-49)

Slides:



Advertisements
Similar presentations
12.5 Sigma Notation and the nth term
Advertisements

E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Workshop Lesson 3: Terminating & Repeating Decimals 7 th Grade.
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Alice in Action with Java Chapter 5 Random Numbers.
Introduction to Computers and Programming Lecture 12: Math.random() Professor: Evan Korth New York University.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
Math class methods & User defined methods Math class methods Math.sqrt(4.0) Math.random() java.lang is the library/package that provides Math class methods.
Review for Midterm 2 Nested loops & Math class methods & User defined methods.
Creating a Power Point Presentation Jason Flear November 29, 2004.
©2004 Brooks/Cole Chapter 6 Methods and Scope. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Method Can Be Viewed as a Black Box To use a.
Unit 7: Sequences and Series. Sequences A sequence is a list of #s in a particular order If the sequence of numbers does not end, then it is called an.
NOTES 2.1 Rational Numbers VOCAB: rational number: is a number that can be written as the ratio of two integers. (a fraction) terminating decimal: is a.
6.5 – Solving Equations with Quadratic Techniques.
2-1 (C) Comparing and Ordering Integers. Vocabulary Rational Number – a number that can be expressed as a fraction. Ex: %4 ½ 4.8.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
computer
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning =greater than.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 4 part 3 GEORGE KOUTSOGIANNAKIS.
Lecture 5.2 Primitive Expression Patterns. © 2006 Pearson Addison-Wesley. All rights reserved A pattern is a general template that can be applied.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
Variables, Data Types, & Constants. Topics & Objectives Declaring Variables Assignment Statement Reserve Words Data Types Constants Packages & Libraries.
Lecture Set 9 Arrays, Collections and Repetition Part C - Random Numbers Rectangular and Jagged arrays.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
***** SWTJC STEM ***** Chapter 3-1 cg 39 Math Class The Math class provides a convenient way to access higher math functions. The Math class is automatically.
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Introduction to Computer Programming Math Random Dice.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
CS221 Random Numbers. Random numbers are often very important in programming Suppose you are writing a program to play the game of roulette The numbers.
8.4 Use Scientific Notation Algebra. Scientific Notation Numbers such as 1,000,000, 153,000 and are written in standard form. Another way to write.
Lecture 5.2 Primitive Expression Patterns. © 2006 Pearson Addison-Wesley. All rights reserved A pattern is a general template that can be applied.
The Math Class Methods Utilizing the Important Math Operations of Java!
Modularity Computer Science 3. What is Modularity? Computer systems are organized into components called modules. The extent to which this is done is.
Chapter 6: Repetition Continued. 2 Validity Checks What’s weak about the following code ? do { s1 = JOptionPane.showInputDialog (“Enter a number: ”);
Random UNPREDICTABLE NUMBERS. A FEW APPLICATIONS THAT USE RANDOM…. Predictions for life expectance used in insurance Business simulations Games (Give.
7/31: Math.random, more methods About DrawLine.java modifications –allow user input –draw a curve Method definitions Math.random()
Integer Exponents. Warm Up Find Each Product or Quotient x x ÷ ÷ x x
Sequences & Series. Sequence: A function whose domain is a set of consecutive integers. The domain gives the relative position of each term of the sequence:
Georgia Institute of Technology More on Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Math Class Mrs. C. Furman September 2, Math frequently used methods NameUse floor()rounds down ceil()rounds up pow(x,y)returns x to the power of.
Random Numbers Random numbers are extremely useful: especially for games, and also for calculating experimental probabilities. Formula for generating random.
11.7 Continued Probability. Independent Events ► Two events are independent if the occurrence of one has no effect on the occurrence of the other ► Probability.
Review for Nested loops & Math class methods & User defined methods.
Let’s not leave anything to chance. How that process to generate random numbers takes places requires some complicated statistics that are outside the.
Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Conditional Control Structures Chapter 5. Goals and Objectives Understand conditional control structures. Demonstrate the use of decision structures to.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
INTRODUCTION TO COMPUTERS 1st exam solution. Question 1 Please answer the following questions: [5%] Show the page before the user pushes the button. [5%]
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Conditional Control Structures Chapter 5 Review. The If Statement The if statement is a conditional control structure, also called a decision structure,
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
8.1 – Sequences and Series. Sequences Infinite sequence = a function whose domain is the set of positive integers a 1, a 2, …, a n are the terms of the.
Sect 7.3: Geometric Sequence A geometric sequence is a pattern of numbers such that to get from one term to the next, you MULTIPLY by the same value.
Javascript Arrays Ch.19. Array definition & for loop var quiz = [85,90,100,0]; // creates an array var ex = []; ex[0] = 89; // add the quiz grades quizTotal.
Subtracting Integers #41.
Chapter 5 The if Statement
1.7 Piecewise Functions Objective: Identify and graph piecewise functions including greatest integer, step, and absolute value functions.
Variables and Data Types
Iterative Constructs Review
JavaScript Functions.
Unit-2 Objects and Classes
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Variables and Data Types
Random number generators
Java Programming Review 1
62 – Sequences and Series Day 1 Calculator Required
Presentation transcript:

Random Numbers

Are a series of numbers that have no pattern to them Ex) 7, 31, 4, 9, 8, 99… Random Numbers are used in… - Computer Games - Lotteries(6-49) - Screen Savers

Math.random  Part of the java.lang package  The random() methods generates a double between 0 and 1.0. For example, double rNum; rNum = Math.random();  A random integer in a range is generated by using the expression: (highNum – lowNum + 1) * Math.random() + lowNum

Examples To generate Random Numbers between 20 and 100 rNum= (100 – 20+1) * Math.random() + 20; To generate Random Numbers between 10 and 50 rNum= (50 – 10+1) * Math.random() + 10;