Generating Random Numbers

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

Foundations of Cryptography Lecture 10 Lecturer: Moni Naor.
Lab #2-4 Follow-Up: Further into Python. Part 3: Random Numbers.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Authors: David N.C. Tse, Ofer Zeitouni. Presented By Sai C. Chadalapaka.
Modeling and Simulation Monte carlo simulation 1 Arwa Ibrahim Ahmed Princess Nora University.
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.
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Discrete Event Simulation How to generate RV according to a specified distribution? geometric Poisson etc. Example of a DEVS: repair problem.
Simulation.
Pseudorandom Number Generators
Random Number Generation
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
K. Desch – Statistical methods of data analysis SS10
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
Properties of Random Numbers
Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.
APPENDIX D RANDOM NUMBER GENERATION
Elec471 Embedded Computer Systems Chapter 4, Probability and Statistics By Prof. Tim Johnson, PE Wentworth Institute of Technology Boston, MA Theory and.
Spread Spectrum Techniques
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
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
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights.
MATH 224 – Discrete Mathematics
Standard Statistical Distributions Most elementary statistical books provide a survey of commonly used statistical distributions. The reason we study these.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
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.
© 2003, Carla Ellis Simulation Techniques Overview Simulation environments emulation exec- driven sim trace- driven sim stochastic sim Workload parameters.
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.
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
Random Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Monte Carlo Methods.
Experimental Method and Data Process: “Monte Carlo Method” Presentation # 1 Nafisa Tasneem CHEP,KNU
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
M ONTE C ARLO SIMULATION Modeling and Simulation CS
Computer simulation Sep. 9, QUIZ 2 Determine whether the following experiments have discrete or continuous out comes A fair die is tossed and the.
Sampling and estimation Petter Mostad
Lab for Remote Sensing Hydrology and Spatial Modeling Dept of Bioenvironmental Systems Engineering National Taiwan University 1/45 GEOSTATISTICS INTRODUCTION.
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.
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.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
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.
MONTE CARLO METHOD DISCRETE SIMULATION RANDOM NUMBER GENERATION Chapter 3 : Random Number Generation.
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.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
Random Numbers All stochastic simulations need to “generate” IID U(0,1) “random numbers” Other random variates coming from other distribution can be generated.
Monte Carlo simulation
Computability and Complexity
Random Number Generators
Complexity 6-1 The Class P Complexity Andrei Bulatov.
Random-Number Generation
Chapter 7 Random Number Generation
Chapter 7 Random-Number Generation
Properties of Random Numbers
Lecture 2 – Monte Carlo method in finance
Cryptography and Network Security Chapter 7
Computer Simulation Techniques Generating Pseudo-Random Numbers
Random Number Generation
Presentation transcript:

Generating Random Numbers

THE GENERATION OF PSEUDO-RANDOM NUMBERS Agenda generating random number uniformly distributed Why they are important in simulation

Why important in General Numerical analysis, random numbers are used in the solution of complicated integrals. In computer programming, random numbers make a good source of data for testing the effectiveness of computer algorithms. Cryptography Random numbers also play an important role in cryptography.

Why it is important in Simulation random numbers are used in order to introduce randomness in the model. In Machine interference Simulation model we assumed constant for most of TIMES (repair time, operational time) that is not the case in general If we are able to observe the operational/repair times of a machine over a reasonably long period, we will find that they are typically characterized by a theoretical or an empirical probability distribution. THEREFORE we should randomly fallow a theoretical or an empirical probability distribution Hence we need uniformly distributed random numbers, to produce random variates or stochastic variates

Recap.. Uniform distribution each member of the family, all intervals of the same length on the distribution's support are equally probable. FIGURE SHOWS THE PDF

Pseudo-Random Numbers there is no such a thing as a single random number we speak of a sequence of random numbers that follow a specified theoretical or empirical distribution To generate physical phenomenon (true random) Unpredictable non reproducible, natural software hardware Thermal noise of a diode, radioactive decay ideal for cryptography, not good for simulation WHY? We need to reproduce the same random numbers

To Generate (cont.) TO mathematical algorithms produce numbers in a deterministic fashion. Start value Seed these numbers appear to be random since they pass a number of statistical tests designed to test various properties of random numbers Therefore they are referred to as pseudo-random numbers. DEBUG on demand generation no need to store uniformly distributed in the space [0, 1] ALTERNATIVE to pseudo-random numbers???

Rule of thumb for accepting random numbers generating random numbers must yield sequences of numbers or bits that are: uniformly distributed statistically independent reproducible, and non-repeating for any desired length.

Methods The congruential method This is a very popular method and most of the available computer code for the generation of random numbers use some variation of this method. Simple Fast Acceptable xi, a, c and m are all non-negative numbers. mixed congruential method. between 0, m-1, Normalizing them [0, 1] divide by m if x0 = 0, a = c = 7, and m = 10 then we can obtain the following sequence of numbers: 7, 6, 9, 0, 7, 6, 9, 0,...

Period The number of successively generated pseudo-random numbers after which the sequence starts repeating itself is called the period. If the period is equal to m, then the generator is said to have a full period Theorems from number theory show that the period depends on m. The larger the value of m, the larger is the period.

guarantee a full period: In particular, the following conditions on a, c, and m guarantee a full period: m and c have no common divisor. a=1(mod r)if r is a prime factor of m. That is, if r is a prime number(divisible only by itself and 1) that divides m, then it divides a-1. a = 1 (mod 4) if m is a multiple of 4. Example Set of A set of such values is: a = 314, 159, 269, c = 453, 806, 245, and m = 2^32 (for a 32 bit machine).

A question ?????? pseudo-random number generator involves a multiplication, an addition and a division. How can we avoid division?? by setting m equal to the size of the computer word What if an overflow occurs We lose only the significant bit which is multiple of m remaining is the remainder To demonstrate m=100 max number Is 99 If a=8, x=2 c=10 result is 26 If x=20 result is axi+c=170 but remainder 70

General congruential methods f(.) is a function of previously generated pseudo-random numbers. A special case of the above general congruential method is the quadratic congruential generator. Special Case a1=a2=1 c=0 m is power of 2

Composite generators We can develop composite generators by combining two separate generators (usually congruential generators). By combining separate generators, one hopes to achieve better statistical behavior than either individual generator. One of the good examples for this type of generator uses the second congruential generator to shuffle the output of the first congruential generator

Tausworthe generators Tausworthe generators are additive congruential generators obtained when the modulus m is equal to 2 to produce bıt streams ai are binary They are too slow since they only produce bits trinomial-based Tausworthe generator

The lagged Fibonacci generators based on the well-known Fibonacci sequence, General form of LFG where 0<j<k, and appropriate initial conditions have been made. combining two previously calculated elements that lag behind the current element utilizing an algebraic operation O. addition, or a subtraction, or a multiplication as well as it can be a binary operation XOR. additive LFG (ALFG). multiplicative LFG (MLFG).

Mersanne Twister

Statistical tests for pseudo-random number generators Not all random-number generators available through programming languages and other software packages have a good statistical behavior. RANDOMNESS OF SEQUENCE OF BITS frequency test, serial test, autocorrelation test, GOODNESS OF FIT runs test, and chi-square test for goodness of fit.

Frequency test (Monobit test) the most fundamental test In a true random sequence, the number of 1’s and 0’s should be about the same This test checks whether this is correct or not complementary error function (erfc) MATLAB , JAVA

HOW TO Generate m pseudo-random numbers and concatenate them into a string of bits. Let the length of this string be n. The 0’s are first converted into –1’s and then the obtained set of -1 and 1 values are all added up. Let Compute the test statistic Compute the P-value Pvalue<0.01 reject

Example let us consider the bit string: 1011010101. Then, Sn = 1-1 +1+1- 1+1-1+1-1+1 = 2 and Sobs=0.6324. For a level of significance α = 0.01, we obtain that P- value = erfc(0.6324) = 0.5271 > 0.01. Thus, the sequence is accepted as being random.

Serial Test There are 2k different ways of combining k bits. Each of these combinations has the same chance of occurring, if the sequence of the k bits is random. The serial test determines whether the number of times each of these combinations occurs is uniformly distributed. k=1 it is frequency test e =sequence of n bits created by a pseudo-random number generator. (recommended min n 100) The serial statistical test checks the randomness of overlapping blocks of k, k-1, k-2 bits found in e

A statistical testing for pseudorandom number generators for cryptographic applications”, NIST special publication 800-22.

Serial Test Step1– obtain e1,e2,e3 Step 2 – compute frequency Augment e by appending its first k-1 bits to the end of the bit string e, and let e1 be the resulting bit string. Likewise, augment e by appending its first k-2 bits to the end of the bit string e, and let e2 be the resulting bit string. Finally, augment e by appending its first k-2 bits to the end of the bit string e, and let e3 be the Step 2 – compute frequency For sequences e1, e2, e3, in overlap k, k-1, k. frequencies fi1,fi2 fi3 represent the frequency of occurrence of the ith k, k-1, k-2 overlapping bit combination Step 3 compute statistics

Serial Test Step 4 –Compute difference statistics Step 5 Compute P values Step 6 If P-value1 or P-value2 < 0.01 then we reject the null hypothesis that the sequence is random, else we accept the null hypothesis that the sequence is random. (0.01 is significance level) As in the frequency test, if the overlapping bit combinations are not uniformly distributed, ΔS 2 and Δ2 S 2 become large that causes the P-values to be small.

Example Serial Test Step 1 Step 2 frequency calculation e = 0011011101, with n=10, and k=3 Step 1 Append the k-1=2 bits e1 = 001101110100. appending the first k-2=1 e2=00110111010 k-3=0 e3 = e = 0011011101. Step 2 frequency calculation For the 3-bit blocks we use e1 For the 2- bit blocks we use e2 For the 1-bit blocks we use e=e3   Frequency C1 f1 C2 1 f2 C3 f3 C4 f4 2 C5 f5 C6 f6 C7 f7 C8 f8   Frequency C1 f1 1 C2 f2 3 C3 f3 C4 f4   Frequency C1 f1 4 C2 1 f2 6

Step3 Compute difference statistics Step 4 calculate P values Since both P-value1 and P-value2 are greater than 0.01, this sequence passes the serial test.

Auto Corelations Let e denote a sequence of n bits created by a pseudo- random number generator. The intuition behind the autocorrelation test is that if the sequence of bits in e is random, then it will be different from another bit string obtained by shifting the bits of e by d positions.

Runs Test The runs test can be used to test the assumption that the pseudo-random numbers are independent of each other. We start with a sequence of pseudo-random numbers in [0,1]. We then look for unbroken subsequences of numbers, where the numbers within each subsequence are monotonically increasing. Such a subsequence is called a run up, and it may be as long as one number.

Chi-square test for goodness of fit This test checks whether a sequence of pseudo-random numbers in [0,1] are uniformity distributed. The chi-square test, in general, can be used to check whether an empirical distribution follows a specific theoretical distribution. In our case, we are concerned about testing whether the numbers produced by a generator are uniformly distributed.

BIBLIOGRAPHY http://en.wikipedia.org/wiki/Uniform_distribution_(continuo us) COMPUTER SIMULATION TECHNIQES HARRY PERROS