R ANDOM N UMBER G ENERATORS Modeling and Simulation CS 313 1.

Slides:



Advertisements
Similar presentations
Generating Random Numbers
Advertisements

Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
File Processing - Indirect Address Translation MVNC1 Hashing Indirect Address Translation Chapter 11.
Computability and Complexity
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.
Assembly Language and Computer Architecture Using C++ and Java
Hash Tables1 Part E Hash Tables  
Random Number Generation
Hash Tables1 Part E Hash Tables  
Hashing General idea: Get a large array
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
Chapter 2 Functions and Graphs
Random Number Generator. Using Software We can generate random number by: 1- table 2- hardware 3-- software Function to generate RN by SW is: 1-rand 2-
APPENDIX D RANDOM NUMBER GENERATION
Bootstrap spatobotp ttaoospbr Hesterberger & Moore, chapter 16 1.
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.
ETM 607 – Random Number and Random Variates
1 Chapter 8 The Discrete Fourier Transform 2 Introduction  In Chapters 2 and 3 we discussed the representation of sequences and LTI systems in terms.
MATH 224 – Discrete Mathematics
SPANISH CRYPTOGRAPHY DAYS (SCD 2011) A Search Algorithm Based on Syndrome Computation to Get Efficient Shortened Cyclic Codes Correcting either Random.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
CS555Spring 2012/Topic 51 Cryptography CS 555 Topic 5: Pseudorandomness and Stream Ciphers.
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
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.
Hashing Chapter 20. Hash Table A hash table is a data structure that allows fast find, insert, and delete operations (most of the time). The simplest.
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)
Hash Tables1   © 2010 Goodrich, Tamassia.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
Linear Feedback Shift Register. 2 Linear Feedback Shift Registers (LFSRs) These are n-bit counters exhibiting pseudo-random behavior. Built from simple.
Great Theoretical Ideas in Computer Science.
© 2004 Goodrich, Tamassia Hash Tables1  
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Validating a Random Number Generator Based on: A Test of Randomness Based on the Consecutive Distance Between Random Number Pairs By: Matthew J. Duggan,
Confidence Interval Estimation For statistical inference in decision making:
1 1 Slide Simulation Professor Ahmadi. 2 2 Slide Simulation Chapter Outline n Computer Simulation n Simulation Modeling n Random Variables and Pseudo-Random.
Discrete Random Variables. Introduction In previous lectures we established a foundation of the probability theory; we applied the probability theory.
Lab for Remote Sensing Hydrology and Spatial Modeling Dept of Bioenvironmental Systems Engineering National Taiwan University 1/45 GEOSTATISTICS INTRODUCTION.
Review of Statistical Terms Population Sample Parameter Statistic.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Pseudo-random-number generators. Random numbers: the numbers generated by a stochastic process They are indispensible in any simulations based on radom.
CS 615: Design & Analysis of Algorithms Chapter 7: Randomized Algorithms (Weiss Chap.: 10.4)
G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1 Statistical Data Analysis: Lecture 5 1Probability, Bayes’ theorem 2Random variables and.
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
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.
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.
1 Copyright © 2015, 2011, and 2008 Pearson Education, Inc. Chapter 1 Functions and Graphs Section 1 Functions.
Hashing Alexandra Stefan.
Hashing Alexandra Stefan.
© 2013 Goodrich, Tamassia, Goldwasser
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
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Validating a Random Number Generator
Quantitative Reasoning
Random Number Generation
Presentation transcript:

R ANDOM N UMBER G ENERATORS Modeling and Simulation CS 313 1

RANDOM NUMBER GENERATORS The usefulness of these programs is limited by the amount of available data What if more data needed? What if the model changed? What if the input data set is small or unavailable? A random number generator addresses all problems. It produces real values between 0.0 and 1.0. The output can be converted to random variable via mathematical transformations. Historically there are three types of generators. Table look-up generators Hardware generators Algorithmic (software) generators 2

RANDOM NUMBER GENERATORS Algorithmic (software) generators Algorithmic generators are widely accepted because they meet all of the following criteria. Randomness - output passes all reasonable statistical tests of randomness Controllability - able to reproduce output, if desired Portability - able to produce the same output on a wide variety of computer systems Efficiency - fast, minimal computer resource requirements Documentation - theoretically analyzed and extensively tested An ideal random number generator produces output such that each value in the interval 0.0 < u < 1.0 is equally likely to occur. A good random number generator produces output that is (almost) statistically indistinguishable from an ideal generator. We will construct a good random number generator satisfying all of our criteria. 3

CONCEPTUAL MODEL Conceptual Model: Choose a large positive integer m. This defines the set X m = {1, 2,..., m − 1} Fill a (conceptual) urn with the elements of X m Each time a random number u is needed, draw an integer x “at random” from the urn and let u = x/m Each draw simulates a sample of an independent identically distributed sequence of Uniform(0,1) random variables. The possible values are 1/m, 2/m,..., (m − 1)/m. It is important that m be large so that the possible values are densely distributed between 0.0 and and 1.0 are impossible, This is important for some random variants. Ideally we would like to draw from the urn independently and with replacement. If so then each of the m - 1 possible values of u would be equally likely to be selected on each draw. For practical reasons, however, we will use a random number generation algorithm that simulates drawing from the urn without replacement. Fortunately, if m is large and the number of draws is small relative to m then the distinction between drawing with and without replacement is largely irrelevant. To turn the conceptual urn model into a specification model we will use a time- tested algorithm suggested by Lehmer. 4

LEHMER’S ALGORITHM (1951) Lehmer’s algorithm for random number generation is defined in terms of two fixed parameters. Modulus m, a fixed large prime integer Multiplier a, a fixed integer in X m The integer sequence x 0, x 1,... is defined by the iterative equation x i+1 = g(x i ) with g(x) = ax mod m x 0 ∈ X m is called the initial seed 5

LEHMER’S ALGORITHM (1951) Because of the mod operator, 0 ≤ g(x) < m However, 0 must not occur since g(0) = 0 Since m is prime, g(x) ≠ 0 if x ∈ X m. If x 0 ∈ X m, then x i ∈ X m for all i ≥ 0. If the multiplier and prime modulus are chosen properly, a Lehmer generator is statistically indistinguishable from drawing from X m with replacement. Note, there is nothing random about a Lehmer generator, For this reason, it is called a pseudo-random generator. 6

INTUITIVE EXPLANATION 7 When ax is divided by m, the remainder is “likely” to be any value between 0 and m − 1 Similar to buying numerous identical items at a grocery store with only dollar bills. a is the price of an item, x is the number of items, and m = 100. The change is likely to be any value between 0 and 99 cents.

PARAMETER CONSIDERATIONS 8 The choice of m is dictated, in part, by system considerations. On a system with 32-bit 2’s complement integer arithmetic, 2 31 − 1 is a natural choice. In general, we want to choose m to be the largest representable prime integer. Given m, the choice of a must be made with great care. Example: Consider the prime modulus m = 13. If the multiplier is a = 6 and the initial seed is x 0 = 1 then the resulting sequence of x's is 1, 6, 10, 8, 9, 2, 12, 7, 3, 5, 4, 11, 1,... Where, as the ellipses indicate, the sequence is actually periodic because it begins to cycle (with a full period of length m - 1 = 12) when the initial seed reappears. The point is that any 12 consecutive terms in this sequence appear to have been drawn at random, without replacement, from the set X 13 = {1, 2,..., 12}.

PARAMETER CONSIDERATIONS Examples: If the multiplier is a = 7 and the initial seed is x 0 = 1 then the resulting full-period sequence of x's is 1, 7, 10, 5, 9, 11, 12, 6, 3, 8, 4, 2, 1,... Randomness is, like beauty, only in the eye of the beholder. Because of the 12, 6, 3 and 8, 4, 2, 1 patterns, however, most people would consider this second sequence to be “less random" than the first. If the multiplier is a = 5 then either 1, 5, 12, 8, 1,... or 2, 10, 11, 3, 2,... or 4, 7, 9, 6, 4,... will be produced, depending on the initial seed x 0 = 1, 2 or 4. This type of less-than-full-period behavior is clearly undesirable because, in terms of our conceptual model of random number generation, this behavior corresponds to first partitioning the set X m into several disjoint subsets (urns), then selecting one subset and thereafter drawing exclusively from it. 9

CENTRAL ISSUES For a chosen (a,m) pair, does the function g(.) generate a full- period sequence? If a full period sequence is generated, how random does the sequence appear to be? Can ax mod m be evaluated efficiently and correctly? Integer overflow can occur when computing ax. 10

FULL PERIOD CONSIDERATIONS Theorem 1: If the sequence x 0, x 1, x 2,... is produced by a Lehmer generator with multiplier a and modulus m then x i = a i x 0 mod m Theorem 2: If x 0 ∈ X m and the sequence x 0, x 1, x 2... is produced by a Lehmer generator with multiplier a and (prime) modulus m then there is a positive integer p with p ≤ m − 1 such that x 0, x 1, x 2... x p−1 are all different and x i+p = x i i = 0, 1, 2,... That is, the sequence is periodic with fundamental period p. In addition (m − 1) mod p = 0. 11

FULL PERIOD MULTIPLIERS 12 If we pick any initial seed x 0 ∈ X m and generate the sequence x 0, x 1, x 2,... then x 0 will occur again. Furthermore, x 0 will reappear at index p that is either m − 1 or a divisor of m − 1 The pattern will repeat forever. We are interested in choosing full-period multipliers where p = m − 1 For the previous example full-period multipliers generate a virtual circular list with m − 1 distinct elements.

FINDING FULL PERIOD MULTIPLIERS 13 Algorithm: This algorithm is a slow-but-sure way to test for a full- period multiplier.

FREQUENCY OF FULL-PERIOD MULTIPLIERS 14 Given a prime modulus m, how many corresponding full-period multipliers are there? Theorem:

FREQUENCY OF FULL-PERIOD MULTIPLIERS Example: If m = 2 31 − 1 = then since the prime decomposition of m − 1 is m − 1 = 2 31 − 2 = 2 ・ 32 ・ 7 ・ 11 ・ 31 ・ 151 ・ 331 The number of full period multipliers is 15

FINDING ALL FULL-PERIOD MULTIPLIERS 16 Once one full-period multiplier has been found, then all others can be found. Algorithm:

FINDING ALL FULL-PERIOD MULTIPLIERS 17 Theorem: If a is any full-period multiplier relative to the prime modulus m then each of the integers a i mod m ∈ X m i = 1, 2, 3,...,m − 1 is also a full-period multiplier relative to m if and only if i and m − 1 are relatively prime.

FINDING ALL FULL-PERIOD MULTIPLIERS Example: If m = 13 then we know from previous example that there are 4 full period multipliers. The other example a = 6 is one. Then, since 1, 5, 7, and 11 are relatively prime to mod 13 = 66 5 mod 13 = mod 13 = mod 13 = 11 Equivalently, if we knew a = 2 is a full-period multiplier 2 1 mod 13 = 22 5 mod 13 = mod 13 = mod 13 = 7 18

FINDING ALL FULL-PERIOD MULTIPLIERS If m = 2 31 − 1 then from the previous example there are integers relatively prime to m − 1. The first few are i = 1, 5, 13, 17, 19. a = 7 is a full-period multiplier relative to m and therefore: 7 1 mod = mod = mod = mod = mod = are full-period multipliers relative to m. 19