Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.

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

Pseudo Random and Random Numbers
High Performance Computing 1 Random Numbers. High Performance Computing 1 What is a random number generator? Most random number generators generate a.
Generating Random Numbers
Random Number Generation Graham Netherton Logan Stelly.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
 1  Outline  generation of random variates  convolution  composition  acceptance/rejection  generation of uniform(0, 1) random variates  linear.
An Introduction to Random Number Generators and Monte Carlo Methods Josh Gilkerson Wei Li David Owen Josh Gilkerson Wei Li David Owen.
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.
Using random numbers Simulation: accounts for uncertainty: biology (large number of individuals), physics (large number of particles, quantum mechanics),
Random Numbers Dick Steflik. Pseudo Random Numbers In most cases we do not want truly random numbers –most applications need the idea of repeatability.
Genetic Algorithms Can Be Used To Obtain Good Linear Congruential Generators Presented by Ben Sproat.
Pseudorandom Number Generators
Statistics.
Random Number Generation
Use and Testing of Pseudo-random Number Generators (PRNGs) A. Matthew Amthor Senior Project 2003.
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
Methods for Tone and Signal Synthesis R.C. Maher ECEN4002/5002 DSP Laboratory Spring 2002.
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
1 Chapter 7 Generating and Processing Random Signals 第一組 電機四 B 蔡馭理 資工四 B 林宜鴻.
APPENDIX D RANDOM NUMBER GENERATION
15-853Page :Algorithms in the Real World Generating Random and Pseudorandom Numbers.
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.
ETM 607 – Random Number and Random Variates
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.
A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG.
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.
Random-Number Generation Andy Wang CIS Computer Systems Performance Analysis.
CPE 619 Random-Number Generation Aleksandar Milenković The LaCASA Laboratory Electrical and Computer Engineering Department The University of Alabama in.

© 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.
Network Security Lecture 19 Presented by: Dr. Munam Ali Shah.
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.
Pseudo-random generators Random Number Generating There are three types of generators table look-up generators hardware generators algorithmic (software)
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.
Random Number Generator. Random number Random number: Uniform distribution on [0,1] Random device: dice, coin -> cannot generate the equal sequence.
Pseudo-random-number generators. Random numbers: the numbers generated by a stochastic process They are indispensible in any simulations based on radom.
The man who knew 28% of mathematics. John Von Neumann ( ) Hans Bethe: Academic seminars (10.
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.
Module 9.2 Simulations. Computer simulation Having computer program imitate reality, in order to study situations and make decisions Applications?
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.
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.
An Introduction to Random Number Generators and Monte Carlo Methods
Random Number Generators
Random-Number Generation
Chapter 7 Random Number Generation
CS 475/575 Slide set 4 M. Overstreet Old Dominion University
Chapter 7 Random-Number Generation
Lecture 2 – Monte Carlo method in finance
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Computer Simulation Techniques Generating Pseudo-Random Numbers
Random Number Generation
Generating Random and Pseudorandom Numbers
Generating Random and Pseudorandom Numbers
Presentation transcript:

Random Numbers

Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable. They are not repeatable. 2.Pseudorandom numbers: Pseudorandom numbers are numbers that appear random, but are obtained in a deterministic, repeatable, and predictable manner.

True Random Numbers Generators  Use one of several sources of randomness –decay times of radioactive material –electrical noise from a resistor or semiconductor –radio channel or audible noise –keyboard timings  some are better than others  usually slower than PRNGs

Pseudorandom Numbers Generators Reasons for pseudorandom numbers: –Flexible policies –Lack of knowledge Generate stochastic processes Decision making (random decision) Numerical analysis (numerical integration) Monte Carlo integration

Pseudorandom Numbers Generators The desirable Properties of Pseudorandom Numbers –Uncorrelated Sequences - The sequences of random numbers should be serially uncorrelated –Long Period - The generator should be of long period (ideally, the generator should not repeat; practically, the repetition should occur only after the generation of a very large set of random numbers). –Uniformity - The sequence of random numbers should be uniform, and unbiased. That is, equal fractions of random numbers should fall into equal ``areas'' in space. Eg. if random numbers on [0,1) are to be generated, it would be poor practice were more than half to fall into [0, 0.1), presuming the sample size is sufficiently large. –Efficiency - The generator should be efficient. Low overhead for massively parallel computations.

How to generate pseudorandom random numbers Random number seed: Virtually all computer methods of random number generation start with an initial random number seed. This seed is used to generate the next random number and then is transformed into a new seed value.

Midsquare Method 1.Start with an initial seed (e.g. a 4-digit integer). 2.Square the number. 3.Take the middle 4 digits. 4.This value becomes the new seed. Divide the number by 10,000. This becomes the random number. Go to 2.

Midsquare Method, example x 0 = 5497 x 1 : =  x 1 = 2170, R 1 = x 2 : =  x 2 = 7089, R 2 = x 3 : =  x 3 = 2539, R 3 = Drawback: Hard to state conditions for picking initial seed that will generate a “good” sequence.

Midsquare Generator, examples “Bad” sequences: x 0 = 5197 x 1 : =  x 1 = 0088, R 1 = x 2 : =  x 2 = 0077, R 2 = x 3 : =  x 3 = 0059, R 3 = x i = 6500 x i+1 : =  x i+1 =2500, R i+1 = x i+2 : =  x i+2 =2500, R i+1 =

Linear Congruential Generator (LCG) Generator Start with random seed Z 0 < m = largest possible integer on machine Recursively generate integers between 0 and M Z i = (a Z i-1 + c) mod m Use U = Z/m for pseudo-random number get (avoid 0 and 1) When c = 0  Called Multiplicative Congruential Generator When c > 0  Mixed LCG

Linear Congruential Generator (LCG) (Lehmer 1951) Let Z i be the i th number (integer) in the sequence Z i = (aZ i-1 +c)mod(m) Z i  {0,1,2,…,m-1} where Z 0 = seed a = multiplier c = increment m = modulus DefineU i = Z i /m (to obtain U(0,1) value)

LCG, example 16-bit machine a = 1217c = 0 Z 0 = 23m = = Z 1 = (1217*23) mod = U 1 = 27991/32767 = Z 2 = (1217*27991) mod = U 2 = 20134/32767 =

An LCG can be expressed as a function of the seed Z 0 THEOREM: Z i = [a i Z 0 +c(a i -1)/(a-1)] mod(m) Proof:By induction on i i=0Z 0 = [a 0 Z 0 +c(a 0 -1)/(a-1)] mod(m) Assume for i. Show that expression holds for i+1 Z i+1 = [aZ i +c] mod(m) = [a {[a i Z 0 +c(a i -1)/(a-1)] mod(m)} +c] mod(m) = [a i+1 Z 0 +ac(a i -1)/(a-1) +c] mod(m) = [a i+1 Z 0 +c(a i+1 -1)/(a-1) ] mod(m)

Examples: Z i = (69069Z i-1 +1) mod 2 32 U i = Z i /2 32 Z i = (65539Z i-1 +76) mod 2 31 U i = Z i /2 31 Z i = ( Z i-1 ) mod ( )U i = Z i /2 31 Z i = Z i-1 mod 2 59 U i = Z i /2 59 What makes one LCG better than another?

Mixed congruential generator is full period if 1.m = 2 B (B is often # bits in word) fast 2.c and m relatively prime (g.c.d. = 1) 3.If 4 divides m, then 4 divides a – 1 (e.g., a = 1, 5, 9, 13,…)

A full period (full cycle) LCG generates all m values before it cycles. Consider Z i = (3Z i-1 +2) mod(9) with Z 0 =7 Then Z 1 = 5 Z 2 = 8 Z 3 = 8 Z j = 8 j = 3,4,5,6,… On the other hand Z i = (4Z i-1 +2) mod(9) has full period. Why?

The period of an LCG is m (full period or full cycle) if and only if —If q is a prime that divides m, then q divides a-1 —The only positive integer that divides both m and c is 1 —If 4 divides m, then 4 divides a-1. Examples Z i+1 = (16807Z i +3) mod (451605), where =7 5, =(2)(3)(2801), =(3)(5)(7)(11)(17)(23) This LCG does not satisfy the first two conditions. Z i+1 = (16807Z i +5) mod ( ) where =7 5, = (2)(3)(2801), = (3 4 )( ) This LCG satisfies all three conditions.

- m = 2 B where B = # bits in the machine is often a good choice to maximize the period. - If c = 0, we have a power residue or multiplicative generator. Note that Z n = (aZ n-1 ) mod(m)  Z n = (a n Z 0 ) mod(m). If m = 2 B, where B = # bits in the machine, the longest period is m/4 (best one can do) if and only if —Z 0 is odd —a = 8k+ 3, k  Z + (5,11,13,19,21,27,…)

Lagged Fibonacci Generators  Similar to Fibonacci Sequence  Increasingly popular  X n = (X n-l + X n-k ) mod m (l>k>0)  l seeds are needed  m usually a power of 2  Maximum period of (2 l -1)x2 M-1 when m=2 M

Add-with-carry & Subtract-with-borrow  Similar to LFG  AWC: X n =(X n-l +X n-k +carry) mod m  SWB: X n =(X n-l -X n-k -carry) mod m

Multiply-with-carry Generators  Similar to LCG  X n =(aX n-1 +carry) mod m

Random Number Generation Other kinds of generators Quadratic Congruential Generator –S new = (a 1 S old 2 + a 2 S old 2 + b) mod L Combination of Generators –Shuffling – L’Ecuyer – Wichman/Hill Tausworthe Generator –Generates sequence of random bits

Assignment Generate 20 Pseudorandom number using: 1.Midsquare Method 2.Multiplicative Linear Congruential Generator (LCG) Generator 3.Mixed Linear Congruential Generator (LCG) Generator