Random number generators

Slides:



Advertisements
Similar presentations
Building Java Programs Chapter 5
Advertisements

Alice in Action with Java Chapter 5 Random Numbers.
Random Numbers Dick Steflik. Pseudo Random Numbers In most cases we do not want truly random numbers –most applications need the idea of repeatability.
Hash Tables1 Part E Hash Tables  
1 Lab Session-9 CSIT-121 Fall 2003 w Random Number Generation w Designing a Game.
Compunet Corporation Programming with Visual Basic.NET Random Number Week # 12 Tariq Ibn Aziz & Kevin Jones.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
©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.
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,
Some Uses of Probability Randomized algorithms –for CS in general –for games and robotics in particular Testing Simulation Solving probabilistic problems.
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning =greater than.
Slide 11-1 Copyright © 2004 Pearson Education, Inc.
Pseudo-random generators Random Number Generating There are three types of generators table look-up generators hardware generators algorithmic (software)
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?
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.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Random numbers. 2 The Random class A Random object generates pseudo-random numbers. –Class Random is found in the java.util package. import java.util.*;
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.
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with 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.
Random numbers in C++ Nobody knows what’s next....
Georgia Institute of Technology More on Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
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)
CSci 162 Lecture 7 Martin van Bommel. Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based.
Let’s not leave anything to chance. How that process to generate random numbers takes places requires some complicated statistics that are outside the.
Chapter 10 Understanding Randomness. Why Be Random? What is it about chance outcomes being random that makes random selection seem fair? Two things: –
Creating and Using Class Methods. Definition Class Object.
COMPUTER PROGRAMMING. Array C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An.
Conditional Control Structures Chapter 5 Review. The If Statement The if statement is a conditional control structure, also called a decision structure,
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
CS 121 – Intro to Programming:Java - Lecture 4 Announcements Course home page: Owl due soon; another.
1 Building Java Programs Chapter 5 Lecture 11: Random Numbers reading: 5.1, 5.6.
Introduction to programming in java Lecture 16 Random.
RANDOM NUMBER GENERATORS MATH CLUB 12/06/2010. WHAT ARE RANDOM NUMBERS? 1, 3, 5, 7, 9, 11, …? 3, 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5 …? 44, 22, 16, 33,
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
The Divisibility & Modular Arithmetic: Selected Exercises
Chapter 5 The if Statement
Strings, conditional statements, Math
Why they aren't really random
Building Java Programs
Building Java Programs
Building Java Programs Chapter 5
Methods Chapter 6.
Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based on input values Some applications.
Iterative Constructs Review
CMPT 201 Functions.
Building Java Programs
C ODEBREAKER Class discussion.
Repetition-Counter control Loop
Random numbers Taken from notes by Dr. Neil Moore
Some Basics for Problem Analysis and Solutions
Understanding Randomness
Understanding Randomness
Interval Estimation.
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
MSIS 655 Advanced Business Applications Programming
Arrays and Collections
Variables and Data Types
Iterative Constructs Review
Building Java Programs
Lecture 12 Recursion part 1 CSE /26/2018.
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Why are arrays useful? We can use arrays to store a large amount of data without declaring many variables. Example: Read in a file of 1000 numbers, then.
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Random Numbers while loop
Building Java Programs
Randomized Algorithms
Randomized Algorithms
Presentation transcript:

Random number generators By Bartek Wohlert and Arrian Torres

What is a random number generator Java uses what is called a Linear Congruential Method to generate a random number Java includes the Random class in the java.util package for generating random numbers.

What is a random number generator? A random number generator is simply enough a tool that allows the person who's making the code to generate a random number. Because the sequence eventually repeats, random number in a computer application are really pseudorandom.

What is a random Number Generator? It can either return a random integer or a random double integer They can have a specified range. i.e: 1-10

Why do we use a random number generator? A random number generator has many different and valuable uses to it For most reasons, using a random number generator can help make a guessing game created in java function much more better For more grander reasons, random number generators are used in lotteries with very difficult algorithms to break.

An example of a random number generator To generate a random number in a range this code is used to do that (high – low + 1) * Math.random() + low Note that high represents the largest number & low the lowest number in the range. To randomly generate a number between 1-10: (10 – 1 + 1) * Math.random() + 1

An example of a random number generator

Variations of a random number generator There are different variants to the random number generator. A basic change that can be done is determining the range that your random number generator You can also generate a number in double or int form Double: 0.0 – 1.0 Int:1-10