CS433 Modeling and Simulation Lecture 15 Random Number Generator Dr. Anis Koubâa 24 May 2009 Al-Imam Mohammad Ibn Saud Islamic University College Computer.

Slides:



Advertisements
Similar presentations
RSLAB-NTU Lab for Remote Sensing Hydrology and Spatial Modeling 1 An Introduction to R Pseudo Random Number Generation (PRNG) Prof. Ke-Sheng Cheng Dept.
Advertisements

Lectures prepared by: Elchanan Mossel Yelena Shvets Introduction to probability Stat 134 FAll 2005 Berkeley Follows Jim Pitman’s book: Probability Section.
Generating Random Numbers
CS433: Modeling and Simulation
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Cryptography and Network Security
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
CPSC 531:Random-Variate Generation
Chapter 8 Random-Variate Generation
Random number generation Algorithms and Transforms to Univariate Distributions.
CDA6530: Performance Models of Computers and Networks Chapter 5: Generating Random Number and Random Variables TexPoint fonts used in EMF. Read the TexPoint.
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Random-Variate Generation. Need for Random-Variates We, usually, model uncertainty and unpredictability with statistical distributions Thereby, in order.
Simulation Modeling and Analysis
Probability Distributions
Probability Distributions
Random Number Generation
Properties of Random Numbers
Chapter 21 Random Variables Discrete: Bernoulli, Binomial, Geometric, Poisson Continuous: Uniform, Exponential, Gamma, Normal Expectation & Variance, Joint.
BY MISS FARAH ADIBAH ADNAN IMK
Random Number Generation Pseudo-random number Generating Discrete R.V. Generating Continuous R.V.
ETM 607 – Random Number and Random Variates
MATH 224 – Discrete Mathematics
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
The Poisson Process. A stochastic process { N ( t ), t ≥ 0} is said to be a counting process if N ( t ) represents the total number of “events” that occur.
MTH 161: Introduction To Statistics
CPSC 531: Probability Review1 CPSC 531:Distributions Instructor: Anirban Mahanti Office: ICT Class Location: TRB 101.
The University of Texas at Arlington Topics in Random Processes CSE 5301 – Data Modeling Guest Lecture: Dr. Gergely Záruba.
0 Simulation Modeling and Analysis: Input Analysis K. Salah 8 Generating Random Variates Ref: Law & Kelton, Chapter 8.
CS433 Modeling and Simulation Lecture 16 Output Analysis Large-Sample Estimation Theory Dr. Anis Koubâa 30 May 2009 Al-Imam Mohammad Ibn Saud University.
Random-Number Generation Andy Wang CIS Computer Systems Performance Analysis.

© 2003, Carla Ellis Simulation Techniques Overview Simulation environments emulation exec- driven sim trace- driven sim stochastic sim Workload parameters.
CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 15 October 2010 Lecture 05: Statistical Analysis Tools.
Module 1: Statistical Issues in Micro simulation Paul Sousa.
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
Stochastic Models Lecture 2 Poisson Processes
1 Chapter 19 Monte Carlo Valuation. 2 Simulation of future stock prices and using these simulated prices to compute the discounted expected payoff of.
Week 21 Conditional Probability Idea – have performed a chance experiment but don’t know the outcome (ω), but have some partial information (event A) about.
Chapter 2 Random variables 2.1 Random variables Definition. Suppose that S={e} is the sampling space of random trial, if X is a real-valued function.
CS433 Modeling and Simulation Lecture 03 – Part 01 Probability Review 1 Dr. Anis Koubâa Al-Imam Mohammad Ibn Saud University
COMP155 Computer Simulation September 8, States and Events  A state is a condition of a system at some point in time  An event is something that.
ETM 607 – Random-Variate Generation
CS433 Modeling and Simulation Lecture 06 – Part 02 Discrete Markov Chains Dr. Anis Koubâa 11 Nov 2008 Al-Imam Mohammad.
Validating a Random Number Generator Based on: A Test of Randomness Based on the Consecutive Distance Between Random Number Pairs By: Matthew J. Duggan,
Stats Probability Theory Summary. The sample Space, S The sample space, S, for a random phenomena is the set of all possible outcomes.
Foundations of Discrete Mathematics Chapter 4 By Dr. Dalia M. Gil, Ph.D.
CS433 Modeling and Simulation Lecture 07 – Part 01 Continuous Markov Chains Dr. Anis Koubâa 14 Dec 2008 Al-Imam.
Random Variable The outcome of an experiment need not be a number, for example, the outcome when a coin is tossed can be 'heads' or 'tails'. However, we.
Chapter 19 Monte Carlo Valuation. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Monte Carlo Valuation Simulation of future stock.
Discrete Random Variables. Introduction In previous lectures we established a foundation of the probability theory; we applied the probability theory.
Lab for Remote Sensing Hydrology and Spatial Modeling Dept of Bioenvironmental Systems Engineering National Taiwan University 1/45 GEOSTATISTICS INTRODUCTION.
Dr. Anis Koubâa CS433 Modeling and Simulation
MATH 256 Probability and Random Processes Yrd. Doç. Dr. Didem Kivanc Tureli 14/10/2011Lecture 3 OKAN UNIVERSITY.
STA347 - week 91 Random Vectors and Matrices A random vector is a vector whose elements are random variables. The collective behavior of a p x 1 random.
CS433 Modeling and Simulation Lecture 11 Continuous Markov Chains Dr. Anis Koubâa 01 May 2009 Al-Imam Mohammad Ibn Saud University.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1 Statistical Data Analysis: Lecture 5 1Probability, Bayes’ theorem 2Random variables and.
Engineering Probability and Statistics - SE-205 -Chap 3 By S. O. Duffuaa.
3/7/20161 Now it’s time to look at… Discrete Probability.
Chapter 3 Generating Uniform Random Variables. In any kind of simulation, we need data, or we have to produce them. Especially in Monte Marco simulation.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
Generating Random Variates
Engineering Probability and Statistics - SE-205 -Chap 3
Al-Imam Mohammad Ibn Saud University Large-Sample Estimation Theory
Random Variates 2 M. Overstreet Spring 2005
Random Number Generators
The Bernoulli distribution
Berlin Chen Department of Computer Science & Information Engineering
Presentation transcript:

CS433 Modeling and Simulation Lecture 15 Random Number Generator Dr. Anis Koubâa 24 May 2009 Al-Imam Mohammad Ibn Saud Islamic University College Computer and Information Sciences

Reading  Required  Chapter 4: Simulation and Modeling with Arena  Chapter 2: Discrete Event Simulation - A First Course,  Optional  Harry Perros, Computer Simulation Technique - The Definitive Introduction, 2007 Chapter 2 and Chapter 3

Goals of Today  Understand the fundamental concepts of Random Number Generators (RNGs)  Lean how to generate random variate for standard uniform distributions in the interval [0,1]  Learn how to generate random variate for any probability distribution

Outline  Why Random Number Generators   Desired Properties of RNGs  Lehmer’s Algorithm  Period and full-period RNGs  Modulus and multiplier selection (Lehmer)  Implementation - overflow

Why Random Number Generators   Random Numbers (RNs) are needed for doing simulations  Generate random arrivals (Poisson), random service times (Exponential)  Random numbers must be Independent (unpredictable) A1 A2 Random Inter-Arrival Time: Exp(A) D1 Random Service Time: Exp(  ) A3 NOW

The Concept  Goal: create random variates for random variables X of a certain distribution defined with its CDF  Approach: Inverse cumulative distribution function CDF F ( x )= u  Cumulative Distribution Function  Generate a random variable  Determine x such that u1u1 X1 Exp u2u2 X1 Poisson X2 Exp X2 Poisson

Problem Statement of RNGs Problem: We want to create a function: u = rand(); that  produces a floating point number u, where 0<u<1 AND  any value strictly greater than 0 and less than 1 is equally likely to occur (Uniform Distribution in ]0,1[ )  0.0 and 1.0 are excluded from possible values

Problem Statement of RNGs  This problem can be simply resolved by the following technique:  For a large integer m, let the set  m = {1, 2, … m-1}  Draw in an integer x   m randomly  Compute: u = x/m m should be very large  Our problem reduces to determining how to randomly select an integer in  m

Lehmer’s Algorithm  The objective of Lehmer’s Algorithm is to generate a sequence of random integers in  m : x 0, x 1, x 2, … x i, x i+1, …  Main idea: Generate the next x i+1 value based on the last value of random integer x i x i+1 = g(x i ) for some function g(.)

Lehmer’s Algorithm  In Lehmer’s Algorithm, g(.) is defined using two fixed parameters  Modulus m : a large, fixed prime integer  Multiplier a : a fixed integer in  m  Then, choose an initial seed  The function g(.) is defined as:  The mod function produces the remainder after dividing the first argument by the second  More precisely: where is the largest integer n such that n≤ x

Observations  The mod function ensures a value lower than m is always produced  If the generator produces the value 0, then all subsequent numbers in the sequence will be zero  (This is not desired)  Theorem if (m is prime and initial seed is non-zero) then the generator will never produce the value 0  In this case, the RNG produces values in  m = {1, 2, … m-1}

Observations  The above equation simulates drawing balls from an urn without replacement, where each value in  m represents a ball  The requirement of randomness is violated because successive draws are not independent  Practical Fact: The random values can be approximately considered as independent if the number of generated random variates (ball draws) is << m The Quality of the random number generator is dependent on good choices for a and m

The Period of a Sequence  Consider sequence produced by:  Once a value is repeated, all the sequence is then repeated itself  Sequence: where  p is the period: number of elements before the first repeat  clearly p ≤ m-1  It can be shown, that if we pick any initial seed x 0, we are guaranteed this initial seed will reappear

Full Period Sequences  [LP] Discrete-Event Simulation: A First Course by L. M. Leemis and S. K Park, Prentice Hall, 2006, page. 42 Theorem  If and the sequence is produced by the Lehmer generator where m is prime, then there is a positive integer p with such that:  are all different  and  In addition,

Full Period Sequences  Ideally, the generator cycles through all values in  m to maximize the number of possible values that are generated, and guarantee any number can be produced  The sequence containing all possible numbers is called a full-period sequence (p = m-1)  Non-full period sequences effectively partition  m into disjoint sets, each set has a particular period.

Modulus and Multiplier Selection Criteria  Selection Criteria 1: m to be “as large as possible”  m = 2 i - 1 where i is the machine precision (is the largest possible positive integer on a “two’s complement” machine)  Recall m must be prime  It happens that is prime (for a 32 bit machine)  Unfortunately, and are not prime ;-(  Selection Criteria 2: p gives full-period sequence (p = m-1)  For a given prime number m, select multiplier a that provide a full period  Algorithm to test if a is a full-period multiplier (m must be prime):

Modulus and Multiplier Selection Criteria  Criterias  m to be “as large as possible”  p gives full-period sequence (p = m-1) p = 1; x = a; // assume, initial seed is x0=1, thus x1=a while (x != 1) {// cycle through numbers until repeat p++; x = (a * x) % m;// careful: overflow possible } if (p == m-1)// a is a full period multiplier else// a is not a full period multiplier Algorithm for finding if p is full-period multiplier

Other Useful Properties Theorem 2.1.1[LP]: If the sequence x 0, x 1, x 2, … is produced by a Lehmer generator with multiplier a and modulus m, then Note this is not a good way to compute x i ! Theorem 2.1.4[LP, p. 45]: If a is any full-period multiplier relative to the prime modulus m, then each of the integers is also a full period multiplier relative to m if and only if the integer i has no prime factors in common with the prime factors of m -1 (i.e., i and m-1 are relatively prime, or co-prime)

Other Useful Properties // Given prime modulus m and any full period multiplier a, // generate all full period multipliers relative to m i = 1; x = a;// assume, initial seed is 1 while (x != 1) {// cycle through numbers until repeat if (gcd(i,m-1)==1) // x=a i mod m is full period multiplier i++; x = (a * x) % m;// careful: overflow possible } Generate all full-period multipliers

Implementation Issues  Assume we have a 32-bit machine, m=  Problem  Must compute  Obvious computation is to compute first, then do mod operation The multiplication might overflow, especially if m-1 is large!  First Solution: Floating point solution  Could do arithmetic in double precision floating point if multiplier is small enough  Double has 53-bits precision in IEEE floating point  May have trouble porting to other machines  Integer arithmetic faster than floating point

Implementation Issues: Mathematical Solutions  Problem: Compute without overflow  General Idea: Perform mod operation first, before multiplication.  Suppose that (not prime)   We have:  Thus, No overflow

 For the case, m is prime, so let  q = quotient; r = remainder  Let  It can be shown that (Page 59, Lemis/Park Textbook) and Implementation Issues: Mathematical Solutions

Random number variants Discrete random variables Continuous random variables Next

The Concept  Goal: create random variates for random variables X of a certain distribution defined with its CDF  Approach: Inverse cumulative distribution function CDF F ( x )= u  Cumulative Distribution Function  Generate a random variable  Determine x such that u1u1 X1 Exp u2u2 X1 Poisson X2 Exp X2 Poisson

Generating Discrete Random Variates Cumulative Distribution Function of X: F(x) = P(X≤x) PDF x F(x) xf(x) u = F(x) 0.5 = F(2) x u Inverse Distribution Function (idf) of X: F*(u) = min {x: u < F(x)} x F(x) x = F*(u) 2 = F(0.5) x u Random variate generation: 1. Select u, uniformly distributed (0,1) 2. Compute F*(u); result is random variate with distribution f() f(x=2)

Discrete Random Variate Generation  Uniform (a,b): equally likely to select an integer in interval [a,b]  Bernoulli(p)  Bernoulli(p):  Return 1 with probability p,  Return 0 with probability 1-p  Geometric(p):  Number of Bernoulli trials until first ‘0’)

Exponential Random Variates  Exponential distribution with mean 