CS 475/575 Slide set 4 M. Overstreet Old Dominion University

Slides:



Advertisements
Similar presentations
Generating Random Numbers
Advertisements

Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.
Pseudorandom Number Generators
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Random Number Generation
Hash Tables1 Part E Hash Tables  
Tirgul 9 Hash Tables (continued) Reminder Examples.
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
Tirgul 7. Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys.
ETM 607 – Random Number and Random Variates
A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
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.
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.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
Searching Given distinct keys k 1, k 2, …, k n and a collection of n records of the form »(k 1,I 1 ), (k 2,I 2 ), …, (k n, I n ) Search Problem - For key.
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,
Quasi-Random Number Sequences from a Long Period TLP Generator with Remarks on Application to Cryptography By Herbert S. Bright and Richard L. Enison Presented.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
CMSC 341 Hashing Readings: Chapter 5. Announcements Midterm II on Nov 7 Review out Oct 29 HW 5 due Thursday CMSC 341 Hashing 2.
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.
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 What is it? A side order for your eggs? A form of narcotic intake? A combination of the two?
Test for randomness : Chi square test
Random Numbers All stochastic simulations need to “generate” IID U(0,1) “random numbers” Other random variates coming from other distribution can be generated.
3. Random Number Generator
Generating Random Numbers
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Hashing Alexandra Stefan.
Hashing Alexandra Stefan.
Random Number Generators
Number Theory (Chapter 7)
Hash functions Open addressing
Random numbers Taken from notes by Dr. Neil Moore
Understanding Randomness
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Random-Number Generation
Random vs pseudo random
Chapter 7 Random Number Generation
Chapter 7 Random-Number Generation
Introduction to Algorithms 6.046J/18.401J
Properties of Random Numbers
Resolving collisions: Open addressing
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Hashing Alexandra Stefan.
Cryptography and Network Security Chapter 7
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Introduction to Algorithms
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Validating a Random Number Generator
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
Analysis of Algorithms
Random Number Generation
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
What we learn with pleasure we never forget. Alfred Mercier
Data Structures and Algorithm Analysis Hashing
Presentation transcript:

CS 475/575 Slide set 4 M. Overstreet Old Dominion University Spring 2005

Random Number Generators Techniques to generate random numbers: (very old) random number tables seldom done even cheap calculators likely to rnd function though who knows how good they are observation of physical phenomena slow, expensive, not reproducible computer generated: find a function f such that given a seed x0,

computer generated (cont.) thus etc. once you pick x0, everything is determined and always produces the same sequence

desirable properties ideally, f should be: small (& easy to code) fast reproducible produce as many values as desired. infinite length is impossible. why? for practical and historical reasons, we usually generate u(0,1) random numbers.

what is “random”? suppose we have a black box which supposedly produces the digits 0 - 9 in random order. if we turn the box on and the 1st digit is 6, is this random? can’t be answered, not enough information “randomness” is a statistical property of a sequence of numbers does not depend on how numbers are generated choice of essential characteristics not scientific but no “patterns”

tests for randomness most seem to be along the line of eliminating undesirable characteristics: frequency counts; about the same number in equal sized subintervals. (what if the box produced 100 integers, but in the order 10 0’s, then 10 1’s ..., etc.) serial tests, the pairs should be uniformly distributed.

tests (cont.) more tests requirements for test: gap test poker test coupon collector’s test permutation test runs up and runs down test monkey test requirements for test: have understood statistical distribution (so you can measure) “strength” of test: if fail test a => fail test b, don’t do b

bad ideas: VonNeumann’s midsquare method (40’s): Knuth’s unpredictable code method (50’s): alg. with “random” (at least hard to anticipate from reading the code) iterations, jumps, shifts, flips, etc.

rng (from Park & Miller, CACM, 10/88) rng goals full period random efficient reproducible proposed by Lehmer in 1951: prime modulus multiplicative linear congruential generator: f(z) = a*z mod m, where m is prime

rng (more) usually want a float in [0,1], so this is good because: ui = zi / m this is good because: 1) since m is prime, 2) 3) randomness of ui is the same as the randomness of zi

rng mod arith example 1) f(z) = 6z mod 13: if start with z = 1, get 1, 6, 10, 8, 9, 2, 12, 7, 3, 5, 4, 11, 1, ... if start with z = 2, what happens? 2) f(z) = 7z mod 13, start with 1, to get 1, 7, 10, 5, 9, 11, 12, 6, 3, 8, 4, 2, 1 3) f(z) = 5z mod 13, start with 1, to get 1, 5, 12, 8, 1, ... start with 2, to get 2, 10, 11, 3, 2, ...

rng (cont.) common choice for modulus is better choice is (why?) better choice is (is this prime?) with this choice of m, still need: a choice for a (P&M recommend 16807) an efficient implementation so f(z) = 16807 * z mod 2147483647. (this generator has been extensively tested)

theory support RNGs using number theory, can ensure max period assume generator is mixed linear congruential of form: here “mixed” means both add & mult. if c=0, then this is a multiplicative linear congruential generator

max period - 1 max period achieved by proper choice of a, c, m, and : if , c=0, longest period, P, is provided: 1) 2) for some integer k

max period - 2 For m prime and c=0, longest period P= m-1 provided: a has the property that the smallest integer k such that is divisible by m is k=m-1.

problem: maximal period not only issue Problems with serial correlation If k random numbers at a time are used to plot points in k-space, the points will not “fill up” the space, but will fall in k-1 planes. At most about m1/k planes. Randu is an infamous example provided by IBM a=65539, c=0, m=231 See ~cs475/plotting. Type “gnuplot” then at prompt type load “plot.triples”

some code: randu /* Bad Example! Do not use!! */ /* Returns values between 0 and 1. */ /* Depends on 32 bit representation for integers. */ double randu( seed ) long int *seed; { long int a = 16807, mod = 2147483647; /* 2^31 - 1 */ double dmod = 2147483647.0; /* 2^31 - 1 */ *seed = *seed * a; if ( *seed < 0 ) *seed += mod; return( ( double ) *seed / dmod ); }

better code: random long int *seed; /* C implementation Park & Miller’s random function */ double random ( seed ) long int *seed; { long int a = 16807, /* 7^5 */ m = 2147483647, /* 2^31 - 1 */ q = 127773, /* m / a (int divide) */ r = 2836, /* m % a */ lo, hi, test; double dm = 2147483647; hi = *seed / q; lo = *seed % q; test = a * lo - r * hi; *seed = test > 0 ? test : test + m; return( (double ) *seed / dm ); }

Reference Leemis, chapter 2.