Random Number Generators

Similar documents
Independent Events. Two events are independent if knowing that one occurs does not change the probability of the other occurring

How does the computer generate observations from various distributions specified after input analysis?

Generating pseudo- random numbers

Department of Electrical- and Information Technology. ETS061 Lecture 3, Verification, Validation and Input

CSCE 564, Fall 2001 Notes 6 Page 1 13 Random Numbers The great metaphysical truth in the generation of random numbers is this: If you want a function

How does the computer generate observations from various distributions specified after input analysis?

Class 12. Random Numbers

Lecture 3. Discrete Random Variables

CPSC 531: Random Numbers. Jonathan Hudson Department of Computer Science University of Calgary

Monte Carlo Simulation

Uniform Random Number Generators

2 Random Variable Generation

B.N.Bandodkar College of Science, Thane. Random-Number Generation. Mrs M.J.Gholba

UNIT 5:Random number generation And Variation Generation

Review of Statistical Terminology

Generating Uniform Random Numbers

Generating Uniform Random Numbers

Random Number Generation. Stephen Booth David Henty

2008 Winton. Review of Statistical Terminology

STAT2201. Analysis of Engineering & Scientific Data. Unit 3

20.1 2SAT. CS125 Lecture 20 Fall 2016

Computer Applications for Engineers ET 601

A simple algorithm that will generate a sequence of integers between 0 and m is:

Generating Uniform Random Numbers

( ) ( ) Monte Carlo Methods Interested in. E f X = f x d x. Examples:

Sources of randomness

Chapter 4: Monte Carlo Methods. Paisan Nakmahachalasint

Lecture 3: Randomness in Computation

B. Maddah ENMG 622 Simulation 11/11/08

1 Poisson processes, and Compound (batch) Poisson processes

4.5 Applications of Congruences

Simulation. Where real stuff starts

IEOR 3106: Introduction to Operations Research: Stochastic Models. Professor Whitt. SOLUTIONS to Homework Assignment 2

Lecture 20. Randomness and Monte Carlo. J. Chaudhry. Department of Mathematics and Statistics University of New Mexico

Probability Density Functions and the Normal Distribution. Quantitative Understanding in Biology, 1.2

Random numbers and generators

ELEG 3143 Probability & Stochastic Process Ch. 2 Discrete Random Variables

x x 1 0 1/(N 1) (N 2)/(N 1)

Stochastic Simulation of

1 Inverse Transform Method and some alternative algorithms

Uniform random numbers generators

NORTHWESTERN UNIVERSITY Tuesday, Oct 6th, 2015 ANSWERS FALL 2015 NU PUTNAM SELECTION TEST

Math Stochastic Processes & Simulation. Davar Khoshnevisan University of Utah

Random Variables Example:

Simulation. Where real stuff starts

1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:

Random Variables. Definition: A random variable (r.v.) X on the probability space (Ω, F, P) is a mapping

IEOR 4703: Homework 2 Solutions

Topics in Computer Mathematics

Introduction to Information Entropy Adapted from Papoulis (1991)

Pseudorandom Generators

2. Variance and Covariance: We will now derive some classic properties of variance and covariance. Assume real-valued random variables X and Y.

Guidelines for Solving Probability Problems

Workshop on Heterogeneous Computing, 16-20, July No Monte Carlo is safe Monte Carlo - more so parallel Monte Carlo

Chapter 2. Random Variable. Define single random variables in terms of their PDF and CDF, and calculate moments such as the mean and variance.

From Random Numbers to Monte Carlo. Random Numbers, Random Walks, Diffusion, Monte Carlo integration, and all that

Pseudo-random Number Generation. Qiuliang Tang

Random variables. DS GA 1002 Probability and Statistics for Data Science.

Probability and Statistics Concepts

Random processes and probability distributions. Phys 420/580 Lecture 20

Physics 403. Segev BenZvi. Monte Carlo Techniques. Department of Physics and Astronomy University of Rochester

Lecture Notes 1 Probability and Random Variables. Conditional Probability and Independence. Functions of a Random Variable

Recall from last time. Lecture 3: Conditional independence and graph structure. Example: A Bayesian (belief) network.

Discrete Probability Distributions

Review of Probability. CS1538: Introduction to Simulations

Systems Simulation Chapter 7: Random-Number Generation

Name: Firas Rassoul-Agha

Hands-on Generating Random

Theoretical Cryptography, Lectures 18-20

CPSC 467: Cryptography and Computer Security

Stochastic Simulation of Communication Networks

Lecture 2 : CS6205 Advanced Modeling and Simulation

2.1 Elementary probability; random sampling

Statistics, Data Analysis, and Simulation SS 2013

6.842 Randomness and Computation Lecture 5

X = X X n, + X 2

Randomized Algorithms

The Derivative of a Function Measuring Rates of Change of a function. Secant line. f(x) f(x 0 ) Average rate of change of with respect to over,

14 Random Variables and Simulation

1: PROBABILITY REVIEW

Lecture 11: Information theory THURSDAY, FEBRUARY 21, 2019

CS 361: Probability & Statistics

Conditional distributions (discrete case)

Scientific Computing: Monte Carlo

Chapter 3. Chapter 3 sections

CSE525: Randomized Algorithms and Probabilistic Analysis April 2, Lecture 1

Chapter 2: Random Variables

Lecture Notes 1 Probability and Random Variables. Conditional Probability and Independence. Functions of a Random Variable

Theoretical Cryptography, Lecture 13

IE 303 Discrete-Event Simulation L E C T U R E 6 : R A N D O M N U M B E R G E N E R A T I O N

Pseudorandom Generators

MCMC notes by Mark Holder

Stream Ciphers. Çetin Kaya Koç Winter / 20

Math 151. Rumbos Fall Solutions to Review Problems for Exam 2. Pr(X = 1) = ) = Pr(X = 2) = Pr(X = 3) = p X. (k) =

Lecture 22. We first consider some constructions of standard commitment schemes. 2.1 Constructions Based on One-Way (Trapdoor) Permutations

Physics 403 Monte Carlo Techniques

1.1 Review of Probability Theory

IE 581 Introduction to Stochastic Simulation. One page of notes, front and back. Closed book. 50 minutes. Score

Pseudorandom Generators

Lecture 1: Probability Fundamentals

Transcription:

1/18 Random Number Generators Professor Karl Sigman Columbia University Department of IEOR New York City USA

2/18 Introduction Your computer generates" numbers U 1, U 2, U 3,... that are considered independent and uniformly randomly distributed on the continuous interval (0, 1). Recall that the probability distribution (cumulative distribution function) of such a uniformly distributed random variable U is given by F(x) = P(U x) = x, x (0, 1), and more generally, for 0 y < x < 1, P(y < U x) = x y. In other words, the probability that U falls in an interval (y, x] is just the length of the interval, x y.

3/18 Introduction Independence means that regardless of the values of the first n random numbers, U 1,..., U n, the value of the next one, U n+1, still has the same uniform distribution over (0, 1); it is not in any way effected by those previous values. This is analogous to sequentially flipping a (fair) coin: regardless of the first n flips, the next one will still land heads (H) or tails (T) with probability 1/2. The sequence of random variables (rvs) U 1, U 2,... is an example of an independent and identically distributed(iid) sequence. Here, the identical distribution is the uniform over (0, 1), which is a continuous analog of equally likely" probabilities.

4/18 Introduction In Python, for example, you can obtain such U as follows: import random U = random.random() Once random is imported, then each time you use the command U = random.random() you receive a new uniform number within [0, 1).

5/18 Introduction It turns out once we have access to such uniform numbers U, we can use them to construct ( simulate/generate") random variables of any desired distribution, construct stochastic processes such as random walks, Markov chains, Poisson processes, renewal processes, Brownian motion and many other processes. Suppose for example, that we want a random variable X that has an exponential distribution at rate λ: The cumulative distribution function (CDF) is given by F(x) = P(X x) = 1 e λx, x 0.

6/18 Introduction Then simply define X = 1 ln (U), λ where ln (y) denotes the natural logarithm of y > 0. Proof: P(X x) = P( 1 ln (U) x) λ = P(ln (U) λx) = P(U e λx ) = 1 e λx. (Recall that P(U y) = 1 y, y (0, 1).)

7/18 Introduction Bernoulli random variables B with any probability = p of "success" can be easily simulated: Define B = I{U p}, where I{A} denotes indicator function of the event A (1 if the event A occurrs, 0 if not.) P(B = 1) = P(U p) = p, P(B = 0) = P(U > p) = 1 p.

8/18 Pseudorandom numbers It turns out that the numbers generated by a computer are not really random nor independent as we said, but what are called Pseudorandom numbers. This means that they appear, for all practical purposes, to be random (and independent) in the sense that they would pass various statistical tests for checking the random/independent property. We thus can use them in our simulations as if they were truly random and we do. Next we will discuss how the computer generates these numbers. This is deeply related to "cryptography" in which one wants to hide important information (from an opponent/enemy) in data that appears" to be random.

9/18 Pseudorandom numbers As an example to get you to think: Suppose I hand you a sequence of zeros and ones: (0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1). I tell you that I flipped a fair coin 25 times where 1 = Head (H), and 0 = Tails (T). How can you check with certainty that I am telling the truth? ANSWER: You can t

10/18 Pseudorandom numbers But if I keep handing you such sequences of various lengths, then you can perform statistical tests that would help you decide if the sequences are consistent with coin flips.

Linear Congruential Generators The most common and easy to understand and implement random number generator is called a Linear Congruential Generator (LCG) and is defined by a recursion as follows: Z n+1 = (az n + c) mod m, n 0, U n = Z n /m, where 0 < a < m, 0 c < m are constant integers, and mod m means modulo m which means you divide by m and leave the remainder. For example 6 mod 4 = 2, 2 mod 4 = 2, 7 mod 4 = 3, 12 mod 4 = 0. Thus all the Z n fall between 0 and m 1; the U n are thus between 0 and 1. 0 Z 0 < m is called the seed. m is chosen to be very large, usually of the form m = 2 32 or m = 2 64 because your computer architecture is based on 32 or 64 bits per word; the modulo computation merely involves truncation by the computer, hence is immediate. 11/18

12/18 Linear Congruential Generators For example if m = 2 3 = 8, then in binary, there are 8 numbers representing {0, 1, 2, 3, 4, 5, 6, 7} given by a 3-tuple of 0s and 1s, denoted by (i 0, i 1, i 2 ) = i 0 2 0 + i 1 2 1 + i 2 2 2, i j {0, 1}, j = 0, 1, 2. Thus, (0, 0, 0) = 0, (1, 0, 0) = 2 0 = 1, (1, 1, 0) = 2 0 + 2 1 = 3, (0, 0, 1) = 2 2 = 4 and (1, 1, 1) = 2 0 + 2 1 + 2 2 = 7, and so on. Note how 7 + 1 = 8 = 0 mod 8 is computed by truncation: (1, 1, 1) + (1, 0, 0) = (0, 0, 0, 1) = 2 3. The last component gets truncated yielding (0, 0, 0) = 0. 10 = (0, 1, 0, 1) gets truncated to (0, 1, 0) = 2, and so on.

13/18 Linear Congruential Generators Here is a more typical example: Z n+1 = (1664525 Z n + 1013904223) mod 2 32. Thus a = 1664525 and c = 1013904223 and m = 2 32 = 4, 294, 967, 296; more than 4.2 billion.

14/18 Linear Congruential Generators The numbers a, c, m must be carefully chosen to get a good" random number generator, in particular we would want all m values 0, 1,... m 1 to be generated in which case we say that the LCG has full period of length m. Such generators will cyclically run thru the numbers over and over again. To illustrate, consider with Z 0 = 0. Then Z n+1 = (5Z n + 1) mod 8, n 0, (Z 0, Z 1,..., Z 7 ) = (0, 1, 6, 7, 4, 5, 2, 3), and Z 8 = 16 mod 8 = 0, hence causing the sequence to repeat.

15/18 Linear Congruential Generators If we increase m to m = 16, Z n+1 = (5Z n + 1) mod 16, n 0, with Z 0 = 0, then (Z 0, Z 1,..., Z 15 ) = (0, 1, 6, 15, 12, 13, 2, 11, 8, 9, 14, 7, 4, 5, 10, 3), and Z 16 = 16 mod 16 = 0, hence causing the sequence to repeat.

16/18 Linear Congruential Generators Choosing good numbers a, c, m involves the sophisticated use of number theory; prime numbers and such, and has been extensively researched/studied by computer scientists and mathematicians for many years. Note that the numbers generated are entirely deterministic: If you know the values a, c, m, then once you know one value (Z 0, say) you know them all. But if you are handed a long sequence of the U n, they certainly appear random, and that is the point.

17/18 Linear Congruential Generators The advantages of using a LCG: 1. Very fast to implement 2. Requires no storage of the numbers, only the most recent value. 3. Replication: Using the same seed, you can generate exactly the same sequence again and again which is extremely useful when comparing alternative systems/models: By using the same numbers you are reducing the variability of differences that would be caused by using different numbers; any difference in the comparisons are thus due to the inherent difference in the models themselves.

18/18 More sophisticated generators Python currently uses the Mersenne Twister as its core random number generator; U = random.random(). It produces at double precision (64 bit), 53-bit precision (floating), and has a period of 2 19937 1 (a Mersenne prime number). The Mersenne Twister is one of the most extensively tested random number generators in existence. (There is both a 32-bit and a 64-bit implementation.) It is not a LCG, it is far more complex, but yet again is deterministic and recursive. The basic Mersenne Twister algorithm continues to be refined and modified over the years to make it faster to implement, etc.