Random Number Generation

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

1 Chi-Square Test -- X 2 Test of Goodness of Fit.
Generating Random Numbers
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Session 2: Secret key cryptography – stream ciphers – part 2.
Outline input analysis input analyzer of ARENA parameter estimation
Random Variable A random variable X is a function that assign a real number, X(ζ), to each outcome ζ in the sample space of a random experiment. Domain.
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.
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Test 2 Stock Option Pricing
Simulation Modeling and Analysis
Probability Densities
Simulation Modeling and Analysis
1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator.
Statistics.
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
Simulation Input and Output Data Analysis
Continuous Random Variables and Probability Distributions
1 Simulation Modeling and Analysis Pseudo-Random Numbers.
Copyright (c) 2004 Brooks/Cole, a division of Thomson Learning, Inc. Chapter 4 Continuous Random Variables and Probability Distributions.
Properties of Random Numbers
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.
Fall 2011 CSC 446/546 Part 6: Random Number Generation.
Random Number Generation Pseudo-random number Generating Discrete R.V. Generating Continuous R.V.
ETM 607 – Random Number and Random Variates
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.
CPSC 531: RN Generation1 CPSC 531:Random-Number Generation Instructor: Anirban Mahanti Office: ICT Class Location:
Chapter 7 Random-Number Generation
CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring.
Tests for Random Numbers Dr. Akram Ibrahim Aly Lecture (9)
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.
Selecting Input Probability Distribution. Simulation Machine Simulation can be considered as an Engine with input and output as follows: Simulation Engine.
Tests of Random Number Generators
ETM 607 – Random-Variate Generation
Chapter 7 Point Estimation of Parameters. Learning Objectives Explain the general concepts of estimating Explain important properties of point estimators.
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.
ICS 253: Discrete Structures I Discrete Probability King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Chapter 5a:Functions of Random Variables Yang Zhenlin.
Review of Probability Concepts Prepared by Vera Tabakova, East Carolina University.
Pseudo-random-number generators. Random numbers: the numbers generated by a stochastic process They are indispensible in any simulations based on radom.
Chapter 14 – 1 Chi-Square Chi-Square as a Statistical Test Statistical Independence Hypothesis Testing with Chi-Square The Assumptions Stating the Research.
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.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
MONTE CARLO METHOD DISCRETE SIMULATION RANDOM NUMBER GENERATION Chapter 3 : Random Number Generation.
Fractiles Given a probability distribution F(x) and a number p, we define a p-fractile x p by the following formulas.
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.
Chapter 4 Particular Methods for Non- Uniform Random Variables.
Test for randomness : Chi square test
IEE 380 Review.
Engineering Probability and Statistics - SE-205 -Chap 3
STAT 312 Chapter 7 - Statistical Intervals Based on a Single Sample
Random-Number Generation
Chapter 7 Random Number Generation
CS 475/575 Slide set 4 M. Overstreet Old Dominion University
Chapter 7 Random-Number Generation
Random-Variate Generation
Properties of Random Numbers
Random Number and Random Variate Generation
Computer Simulation Techniques Generating Pseudo-Random Numbers
Random Number Generation
Random Variate Generation
Presentation transcript:

Random Number Generation 21/07/1438 Random Number Generation Concern with generating random numbers that have the following conditions: Uniformity Independence Efficiency Replicability Long Cycle Length 30

Random Number Generation (cont.) 21/07/1438 Random Number Generation (cont.) Each random number Rt is an independent sample drawn from a continuous uniform distribution between 0 and 1 ì1 , 0 £ x £ 1 pdf: f(x) = í î0 , otherwise 30

Random Number Generation (cont.) 21/07/1438 Random Number Generation (cont.) x f(x) 1 PDF: 30

Techniques for Generating Random Number 21/07/1438 Techniques for Generating Random Number MidSquare Example: X0 = 7182 (seed) = 51581124 ==> R1 = 0.5811 = (5811) 2 = 33767721 ==> R2 = 0.7677 etc. 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) Note: Do not choose a seed that guarantees that the sequence will not degenerate and will have a long period. Also, zeros, once they appear, are carried in subsequent numbers. Ex1: X0 = 5197 (seed) = 27008809 ==> R1 = 0.0088 = 00007744 ==> R2 = 0.0077 Ex2: X0 = 4500 (seed) = 20250000 ==> R1 = 0.2500 = 06250000 ==> R2 = 0.2500 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) Multiplicative Congruential Method: Basic Relationship Xi+1 = a Xi (mod m), where a ³ 0 and m ³ 0 Most natural choice for m is one that equals to the capacity of a computer word. m = 2b (binary machine), where b is the number of bits in the computer word. m = 10d (decimal machine), where d is the number of digits in the computer word. 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) The max period (P) is: For m a power of 2, say m = 2b, the longest possible period is P = m / 4 = 2b-2 This is achieved provided that the seed X0 is odd and the multiplier, a, is given by a = 3 + 8k or a = 5 + 8k, for some k = 0, 1,... 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) For m a prime number, the longest possible period is P = m - 1, This is achieved provided that the multiplier, a, has the property that the smallest integer k such that ak - 1 is divisible by m is k = m - 1, 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) (Example) Using the multiplicative congruential method, find the period of the generator for a = 13, m = 26, and X0 = 1, 2, 3, and 4. The solution is given in next slide. When the seed is 1 and 3, the sequence has period 16. However, a period of length eight is achieved when the seed is 2 and a period of length four occurs when the seed is 4. 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) Period Determination Using Various seeds i Xi Xi Xi Xi 0 1 2 3 4 1 13 26 39 52 2 41 18 59 36 3 21 42 63 20 4 17 34 51 4 5 29 58 23 6 57 50 43 7 37 10 47 8 33 2 35 9 45 7 10 9 27 11 53 31 12 49 19 13 61 55 14 25 11 15 5 15 16 1 3 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) SUBROUTINE RAN(IX, IY, RN) IY = IX * 1220703125 IF (IY) 3,4,4 3: IY = IY + 214783647 + 1 4: RN = IY RN = RN * 0.4656613E-9 IX = IY RETURN END 30

Techniques for Generating Random Number (cont.) 21/07/1438 Techniques for Generating Random Number (cont.) Linear Congruential Method: Xi+1 = (aXi + c) mod m, i = 0, 1, 2.... (Example) let X0 = 27, a = 17, c = 43, and m = 100, then X1 = (17*27 + 43) mod 100 = 2 R1 = 2 / 100 = 0.02 X2 = (17*2 + 43) mod 100 = 77 R2 = 77 / 100 = 0.77 ......... 30

Test for Random Numbers 21/07/1438 Test for Random Numbers 1. Frequency test. Uses the Kolmogorov-Smirnov or the chi-square test to compare the distribution of the set of numbers generated to a uniform distribution. 2. Runs test. Tests the runs up and down or the runs above and below the mean by comparing the actual values to expected values. The statistic for comparison is the chi-square. 3. Autocorrelation test. Tests the correlation between numbers and compares the sample correlation to the expected correlation of zero. 30

Test for Random Numbers (cont.) 21/07/1438 Test for Random Numbers (cont.) 4. Gap test. Counts the number of digits that appear between repetitions of a particular digit and then uses the Kolmogorov-Smirnov test to compare with the expected number of gaps. 5. Poker test. Treats numbers grouped together as a poker hand. Then the hands obtained are compared to what is expected using the chi-square test. 30

Test for Random Numbers (cont.) 21/07/1438 Test for Random Numbers (cont.) In testing for uniformity, the hypotheses are as follows: H0: Ri ~ U[0,1] H1: Ri ¹ U[0,1] The null hypothesis, H0, reads that the numbers are distributed uniformly on the interval [0,1]. 30

Test for Random Numbers (cont.) 21/07/1438 Test for Random Numbers (cont.) In testing for independence, the hypotheses are as follows; H0: Ri ~ independently H1: Ri ¹ independently This null hypothesis, H0, reads that the numbers are independent. Failure to reject the null hypothesis means that no evidence of dependence has been detected on the basis of this test. This does not imply that further testing of the generator for independence is unnecessary. 30

The Chi squared test Divide the interval [0,1] into k equal subintervals. The expected number of true random numbers in each interval is n/k. Let fi denote the number of pseudo random numbers that fall in the ith interval Let If we accept the hypothesis that these random umbers are truly random numbers with significance level a

Generating Bernoulli Random Variable To generate B(p), p: success probability Generate a uniform random number u between [0,1]. If u≤ p then let X = 1 Else let X = 0

Generating general discrete Random Variats We want to generate random variables given the following probability mass function: X Pmf p(X) CDF F(X) x1 p1 x2 p2 p1+ p2 xn pn p1+ p2+ …+ pn

Generating Discrete RV Cont. Generate a uniform random number u between [0,1]. If u≤ p1 then let X = x1 Else if p1+ p2+ …+ pj < u ≤ p1+ p2+ …+ p(j+1) Then let X = xj 0 p1 p2 p3 p4 p5 . . . 1

Generating Continuous RV. Uniform [a,b] Generate a uniform random number u on [0,1] Return X = a + (b-a) u

Inverse transformation Method X has a pdf f(x) And has a continuous CDF F(x) Then Generate a uniform RN u e [0,1] Return X = F-1 (u) Example: Exponential RV with rate l : Generate u e [0,1] uniformly Return X = -1/l ln(1-u) (ln is the natural Logarithm) or simply X = -1/l ln(u)