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

Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
CSE 311 Foundations of Computing I Lecture 13 Number Theory Autumn 2012 CSE
Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.
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.
Use of moment generating functions. Definition Let X denote a random variable with probability density function f(x) if continuous (probability mass function.
Computability and Complexity 20-1 Computability and Complexity Andrei Bulatov Random Sources.
Using random numbers Simulation: accounts for uncertainty: biology (large number of individuals), physics (large number of particles, quantum mechanics),
Today Today: Chapter 5 Reading: –Chapter 5 (not 5.12) –Suggested problems: 5.1, 5.2, 5.3, 5.15, 5.25, 5.33, 5.38, 5.47, 5.53, 5.62.
1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator.
Pseudorandom Number Generators
Statistics.
MISC.. 2 Integration Formula for consumer surplus Income stream - revenue enters as a stream - take integral of income stream to get total revenue.
Random Number Generation
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
Continuous Random Variables and Probability Distributions
1 Chapter 7 Generating and Processing Random Signals 第一組 電機四 B 蔡馭理 資工四 B 林宜鴻.
Chapter 21 Random Variables Discrete: Bernoulli, Binomial, Geometric, Poisson Continuous: Uniform, Exponential, Gamma, Normal Expectation & Variance, Joint.
Random-Number Generation. 2 Properties of Random Numbers Random Number, R i, must be independently drawn from a uniform distribution with pdf: Two important.
Random Number Generation Fall 2013
Random Number Generation Pseudo-random number Generating Discrete R.V. Generating Continuous R.V.
Pseudo-random Number Generation Qiuliang Tang. Random Numbers in Cryptography ► The keystream in the one-time pad ► The secret key in the DES encryption.
ETM 607 – Random Number and Random Variates
MATH 224 – Discrete Mathematics
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.
Functions of Random Variables. Methods for determining the distribution of functions of Random Variables 1.Distribution function method 2.Moment generating.
Random Numbers CSE 331 Section 2 James Daly. Randomness Most algorithms we’ve talked about have been deterministic The same inputs always give the same.
PROBABILITY AND STATISTICS FOR ENGINEERING Hossein Sameti Department of Computer Engineering Sharif University of Technology Two Functions of Two Random.
Functions of Random Variables. Methods for determining the distribution of functions of Random Variables 1.Distribution function method 2.Moment generating.
Random-Number Generation Andy Wang CIS Computer Systems Performance Analysis.
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.
Chapter 7 Random-Number Generation
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.
Use of moment generating functions 1.Using the moment generating functions of X, Y, Z, …determine the moment generating function of W = h(X, Y, Z, …).
Modeling and Simulation Random Number Generators
Continuous Distributions The Uniform distribution from a to b.
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.
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.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
Expectation for multivariate distributions. Definition Let X 1, X 2, …, X n denote n jointly distributed random variable with joint density function f(x.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
Random Number Generator. Random number Random number: Uniform distribution on [0,1] Random device: dice, coin -> cannot generate the equal sequence.
Expectation. Let X denote a discrete random variable with probability function p(x) (probability density function f(x) if X is continuous) then the expected.
Review of Probability. Important Topics 1 Random Variables and Probability Distributions 2 Expected Values, Mean, and Variance 3 Two Random Variables.
1 7.5 CONTINUOUS RANDOM VARIABLES Continuous data occur when the variable of interest can take on anyone of an infinite number of values over some interval.
Continuous Random Variables and Probability Distributions
Pseudo-random-number generators. Random numbers: the numbers generated by a stochastic process They are indispensible in any simulations based on radom.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
Gil McVean, Department of Statistics Thursday February 12 th 2009 Monte Carlo simulation.
G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1 Statistical Data Analysis: Lecture 5 1Probability, Bayes’ theorem 2Random variables and.
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.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
Random Numbers All stochastic simulations need to “generate” IID U(0,1) “random numbers” Other random variates coming from other distribution can be generated.
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.
CSE 311 Foundations of Computing I Lecture 11 Modular Exponentiation and Primes Autumn 2011 CSE 3111.
Generating Random Variates
3. Random Number Generator
The Bernoulli distribution
Some Rules for Expectation
Probability Review for Financial Engineers
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Further Topics on Random Variables: Derived Distributions
Further Topics on Random Variables: Derived Distributions
Further Topics on Random Variables: Derived Distributions
Generating Random Variates
Uniform Probability Distribution
Presentation transcript:

3. Random Number Generator

The Roulette and Dice Mechanical random number generators Roulette picture from http://www.pierceproductions.net/3D/images/Roulette.JPG Die picture from http://blades.netppl.fi/suomi/images/dice.gif Mechanical random number generators

What is a Random Number? Follow a definite distribution, usually uniform distribution Uncorrelated Unpredictable See D Knuth, “Art of Computer Programming”, Vol 2, for more detailed treatment regarding random numbers. 1 3 7 4

Pseudo-Random Numbers Truly random numbers can not be generated on a computer Pseudo-random numbers follow a well-defined algorithm, thus predictable and repeatable Have nearly all the properties of true random numbers

Linear Congruential Generator (LCG) One of the earliest and also fastest algorithm: xn+1 = (a xn + c ) mod m where 0 ≤ xn < m, m is the modulus, a is multiplier, c is increment. All of them are integers. Choice of a, c, m must be done with special care. Perhaps the first random number generator proposed was that of mid-square by von Neumann, but this method does not work well. The following site points to many random number generators – theory and codes: http://random.mat.sbg.ac.at/links/rando.html

Choice of Parameters Name m a (multiplier) c period ANSI C [rand()] 231 1103515245 12345 Park-Miller NR ran0() 231-1 16807 231-2 drand48() 248 25214903917 11 Hayes 64-bit 264 6364136223846793005 1 The site http://crypto.mat.sbg.ac.at/results/karl/server/server.html has a comprehensive list of linear generators. (a x + c) mod m

Short-Coming of LCG When (xn,xn+1) pairs are plotted for all n, a lattice structure is shown. xn+1 Why the lattice structure? xn

Other Modern Generators Mersenne Twister Extremely long period (219937-1), fast Inversive Congruential Generator xn = a xn+1 + c mod m where m is a prime number Nonlinear, no lattice structure The site http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html has source code in C for the Mersenne Twister random number generator. For the inversive congruential generator, check up H. Niederreiter. Three different random number generators are also available (in the file rand.c) at: http://staff.science.nus.edu.sg/~phywjs/BeijingWorkshop.html

Pick an Integer at Random Suppose we want to select an integer j from 0 to N-1 with equal probability. This can be done with: j = N*x; where 0  x < 1 is uniformly distributed random number. For 2D lattice, we can also do this if we name the lattice site sequentially.

Pick j with Probability Pj Since Sj Pj=1, we pick out j if x is in the corresponding interval. P0 P1 x 1 P=p[0]; j = 0; x = drand64(); while(x>P) {++j; P+=p[j]};

Pei Lucheng’s Method Use j = N*x to get an index; pick a final result based on the relative height. This is an O(1) algorithm. This method is also discussed in Knuth’s book, “The Art of Computer Programming”, 3rd ed, Vol 2, page 120. 1 4 2 1 2 3 4 5

Non-Uniformly Distributed Random Numbers Let F(x) be the cumulative distribution function of a random variable x, then x can be generated from x = F-1(ξ) where ξ is uniformly distributed between 0 and 1, and F-1(x) is the inverse function of F(x). This method works only for distribution in one variable.

Proof of the Inverse Method The Mapping from x to ξ is one-to-one. The probability for ξ between value ξ and dξ is 1·dξ, which is the same as the probability for x between value x and dx. Thus dξ = dF(x) = F’(x)dx = p(x)dx, since F-1 (ξ)=x, or ξ = F(x)

Example 1, Exponential Distribution P(x) = exp(-x), x ≥ 0, then So we generate x by x = -log(ξ) where ξ is a uniformly distributed random number. Why not x = -log(1-ξ)?

Example 2, Gaussian distribution Take 2D Gaussian distribution Work in polar coordinates:

Box-Muller Method The formula implies that the variable θ is distributed uniformly between 0 and 2π, ½r2 is exponentially distributed, we have ξ1 and ξ2 are two independent, uniformly distributed random numbers.