Random Numbers Dick Steflik. Pseudo Random Numbers In most cases we do not want truly random numbers –most applications need the idea of repeatability.

Slides:



Advertisements
Similar presentations
Savitch N/A Randomness In Programming Simulations
Advertisements

Generating Random Numbers
Random Number Generation Graham Netherton Logan Stelly.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Random Numbers In today’s lesson we will look at: why we might want a random number whether they really are random how to create and scale random numbers.
The Divisibility & Modular Arithmetic: Selected Exercises Goal: Introduce fundamental number theory concepts: The division algorithm Congruences Rules.
Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.
Algorithm Analysis (Big O) CS-341 Dick Steflik. Complexity In examining algorithm efficiency we must understand the idea of complexity –Space complexity.
Simulation Where real stuff starts. ToC 1.What, transience, stationarity 2.How, discrete event, recurrence 3.Accuracy of output 4.Monte Carlo 5.Random.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Algorithm Analysis (Big O) CS-341 Dick Steflik. Complexity In examining algorithm efficiency we must understand the idea of complexity –Space complexity.
Stream cipher diagram + + Recall: One-time pad in Chap. 2.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator.
Simulation.
Programming Assignment 8 CS113 Spring Programming Assignment 8 Implement the sorting routine of your choice. Compare average performance of your.
Random Number Generation
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
CS 280 Data Structures Professor John Peterson. Big O Notation We use a mathematical notation called “Big O” to talk about the performance of an algorithm.
Methods for Tone and Signal Synthesis R.C. Maher ECEN4002/5002 DSP Laboratory Spring 2002.
Repetition Structures: Do-while Loop Random Number Generation CSC 1401: Introduction to Programming with Java Week 6 Wanda M. Kunkle.
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.
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
Randomized Algorithms. Introduction Algorithm uses a random number to make at least one decision Running time depends on input and random numbers generated.
ETM 607 – Random Number and Random Variates

© 2003, Carla Ellis Simulation Techniques Overview Simulation environments emulation exec- driven sim trace- driven sim stochastic sim Workload parameters.
Basic Concepts in Number Theory Background for Random Number Generation 1.For any pair of integers n and m, m  0, there exists a unique pair of integers.
Modeling and Simulation Random Number Generators
Hashing functions Have many uses. We can use them to hash values into a hashing table, but they have more general uses such as computing a unique identifier.
Random Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Pseudo-random generators Random Number Generating There are three types of generators table look-up generators hardware generators algorithmic (software)
Monte Carlo Methods.
Comp 335 File Structures Hashing.
Monte Carlo Methods So far we have discussed Monte Carlo methods based on a uniform distribution of random numbers on the interval [0,1] p(x) = 1 0  x.
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
CS101 Computer Programming I Chapter 4 Extra Examples.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
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.
Random Number Generator. Random number Random number: Uniform distribution on [0,1] Random device: dice, coin -> cannot generate the equal sequence.
Network Security Lecture 18 Presented by: Dr. Munam Ali Shah.
Arrival & Service Times for Assignment 3 Byung-Hyun Ha
The Art of Programming. The process of breaking problems down into smaller, manageable parts By breaking the problem down, each part becomes more specific.
Random Numbers RANDOM VS PSEUDO RANDOM. Truly Random numbers  From Wolfram: “A random number is a number chosen as if by chance from some specified distribution.
Invasion Percolation: Randomness Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Let’s not leave anything to chance. How that process to generate random numbers takes places requires some complicated statistics that are outside the.
The man who knew 28% of mathematics. John Von Neumann ( ) Hans Bethe: Academic seminars (10.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
Review. Problem 1 What is the output of the following piece of code void increment(int x) { x++; } int main() { int y = 10; increment(y); cout
CSE202: Lecture 13The Ohio State University1 Function Scope.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
1 Generating Random Numbers Textbook ch.6, pg
Module 9.2 Simulations. Computer simulation Having computer program imitate reality, in order to study situations and make decisions Applications?
CS 31 Discussion, Week 2 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:30-1:30pm (today)
UNIFORM RANDOM NUMBER GENERATION Chapter 7 (first half) The goal is to generate a sequence of The goal is to generate a sequence of Uniformly distributed.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
Mathematics 202 Linear Algebra and Probability Spring 2011 Professor Allan B. Cruse Mathematics and Computer Science.
Why they aren't really random
Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based on input values Some applications.
Random Number Generators
Random numbers Taken from notes by Dr. Neil Moore
Random Number Generation
Procedural Terrain Generation
Random vs pseudo random
Lecture 2 – Monte Carlo method in finance
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Random number generators
CS150 Introduction to Computer Science 1
Random Number Generation
Presentation transcript:

Random Numbers Dick Steflik

Pseudo Random Numbers In most cases we do not want truly random numbers –most applications need the idea of repeatability to be able to debug if we used truly random numbers how would we be able to debug a program, every time we would run the program it would be a different problem What we really want is something that will appear to be random but will be able to reproduce a sequence

Generation Uniform Random Numbers Consider a methos for generating a sequence of random fractions (Random real numbers ) U n uniformly distributed between 0 and 1 Since a computer can only represent a real number with finite accuracy we’ll actually generate integers X n between 0 and some number m The fraction U n = X n / m – will always be between 0 and 1 Usually m is the word size of the computer so that X n can be regarded as the integer content of of a computer word with the radix point assumed at the far-right. Un can be regarded as the contents of the same word with the radix point at the far-left.

The Linear Congruential Method By far the most popular random number generators in use today are special cases of the following scheme, introduced by D.H.Lehmer in Choose 4 “magic numbers: m,the modulus;m > 0 a,the multiplier;0 <= a < m c,the increment;0 <= c < m X 0 the Starting value;0 <= Xo < m The desired sequence is then: X n+1 = (aX n + c) mod m,n >= 0 This is called a linear congruential sequence

Example For m = 10 ; X 0 = a = c = 7 the sequence is 7, 6, 9, 0, 7, 6, 9, 0 notice: that the sequence has a period of 4; I.e. it repeats and will do so forever. This will happen for any linear congruential generator.

Sample #include int seed; int random() { int num = (13*seed+11) % 11; seed = num; return num; } int main() { cout << "input a seed number = "; cin >> seed; cout << "\n"; for int j = 0 ; j < 20 ; j++) cout << random() << " "; }