FSU CIS 5930r - Lecture 25 Random Number Generation

Unformatted text preview:

Slide 1Generate Random ValuesBackgroundExampleBasic TermsCycle LengthMore TermsQuestionTypes of Random-Number GeneratorsLinear-Congruential Generators(Mixed) Linear-Congruential Generators (LCG)The Choice of a, b, and mThe Choice of a, b, and mFull-Period GeneratorsMultiplicative LCGMultiplicative LCG with m = 2kMultiplicative LCG with m ≠ 2kMultiplicative LCG with m ≠ 2kMultiplicative LCG with m ≠ 2kTausworthe GenerationsTausworthe ExampleTausworthe ExampleTausworthe Generator CharacteristicsTausworthe ExampleTausworthe ImplementationExtended Fibonacci GeneratorsCombined GenerationsCombined GeneratorsCombined GeneratorsCombined GeneratorsA Survey of Random-number GeneratorsSeed SelectionSeed Selection GuidelinesSeed Selection GuidelinesSeed Selection GuidelinesSeed Selection GuidelinesMyths About Random-number GenerationMyths about Random- number GenerationMyths about Random- number GenerationMyths about Random- number GenerationMyths about Random- number GenerationMore on Random Number GenerationsWhite SlideRandom-Number GenerationAndy WangCIS 5930-03Computer SystemsPerformance AnalysisGenerate Random Values•Two steps–Random-number generation•Get a sequence of random numbers distributed uniformly between 0 and 1–Random-variate generation•Transform the sequence to produce random values satisfying the desired distribution23Background•The most common method–Use a recursive functionxn = f(xn-1, xn-2, …)Example•xn = (5xn-1 + 1) %16–Suppose x0 = 5–The first 32 numbers are between 0 and 15•Divide xn by 15 to get numbers between 0 and 140 5 10 15 20 25 30 350246810121416nth numberrandom number0 5 10 15 20 25 30 3500.10.20.30.40.50.60.70.80.91nth numberrandom numberBasic Terms•x0 = seed–Given a function, the entire sequence can be regenerated with x0•Generated numbers are pseudo random–Deterministic –Can pass statistical tests for randomness–Preferred to fully random numbers so that simulated results can be repeated5Cycle Length•Note that starting with the 17th number, the sequence repeats–Cycle length of 1660 5 10 15 20 25 30 3500.10.20.30.40.50.60.70.80.91nth numberrandom numberMore Terms•Some generators do not repeat the initial part (tail) of the sequence•Period of a generator = tail + cycle length7tail cycle lengthperiodQuestion•How to choose seeds and random-number generation functions?1. Efficiently computable•Heavily used in simulations2. The period should be large3. Successive values should be independent and uniformly distributed8Types of Random-Number Generators•Linear-congruential generators•Tausworth generators•Extended Fibonacci generators•Combined generators•Others910Linear-Congruential Generators•In 1951, Lehmer found residues of successive powers of a number have good randomness propertiesxn = an % m = aan-1 % m = axn-1 % m•Lehmer’s choices of a and ma = 23 (multiplier)m = 108 + 1 (modulus)•Implemented on ENIAC(Mixed) Linear-Congruential Generators (LCG)•xn = (axn-1 + b) % m•xn is between 0 and m – 1•a and b are non-negative integers•“Mixed”  using both multiplication by a and addition by b 11The Choice of a, b, and m•m should be large–Period is never longer than m•To compute % m efficiently–Make m = 2k–Just truncate the result by k bits12The Choice of a, b, and m•If b > 0, maximum period m is obtained when–m = 2k–a = 4c + 1–b is odd–c, b, and k are positive integers13Full-Period Generators•Generators with maximum possible periods•Not equally good–Look for low autocorrelations between successive numbers–xn = ((234 + 1)xn-1 + 1) % 235 has an autocorrelation of 0.25–xn = ((218 + 1)xn-1 + 1) % 235 has an autocorrelation of 2-1814Multiplicative LCG•xn = axn-1 % m, b = 0•Can compute more efficiently when m = 2k•However, maximum period is only 2k-2•Problem: Cyclic patterns with lower bits15Multiplicative LCG with m = 2k•When a = 8i ± 3–E.g., xn = 5xn-1 % 25•Period is only 8•Which is ¼ of 25•When a ≠ 8i ± 3–E.g., xn = 7xn-1 % 25•Period is only 4160 5 10 15 20 25 30 35051015202530nth numberrandom number0 5 10 15 20 25 30 35051015202530nth numberrandom numberMultiplicative LCG with m ≠ 2k•To get a longer period, use m = prime number–With proper choice of a, it is possible to get a period of m – 1–a needs to be a prime root of m•If and only if an % m ≠ 1 for n = 1..m - 217Multiplicative LCG with m ≠ 2k•xn = 3xn-1 % 31–x0 = 1–Period is 30–3 is a prime root of 31180 5 10 15 20 25 30 35051015202530nth numberrandom numberMultiplicative LCG with m ≠ 2k•xn = 75xn-1 % (231 – 1)–75 is a prime root of 231 – 1–But watch out for computational errors•Multiplication overflow–Need to apply tricks mentioned in p. 442•Truncation due to the number of digits available1920Tausworthe Generations•How to generate large random numbers?•The Tausworthe generator produces a random sequence of binary digits–The generator then divides the sequence into strings of desired lengths–Based on a characteristic polynomialTausworthe Example•Suppose we use the following characteristic polynomialx7 + x3 + 1–The corresponding generation function is•bn+7  bn+3  bn = 0Or•bn = bn-4  bn-7–Need a 7-bit seed21Tausworthe Example•The bit stream sequence1111111000011101111001011001….•Convert to random numbers between 0 and 1, with 8-bit numbersx0 = 0.111111102 = 0.9921910x1 = 0.000111012 = 0.1132810x2 = 0.111001012 = 0.8945310…22Tausworthe Generator Characteristics•For the L-bit numbers generated+E[xn] = ½+V[xn] = 1/12+The serial correlation is zero+ Good results over the complete cycle- Poor local behavior within a sequence23Tausworthe Example•If a characteristic polynomial of order q has a period of 2q – 1, it is a primitive polynomial•For x7 + x3 + 1•q = 7•Sequence repeats after 127 bits = 27 - 1•A primitive polynomial24Tausworthe Implementation•Can be easily generated via linear-feedback shift-registers•For x5 + x3 + 125bnbn-1bn-2bn-3bn-4bn-526Extended Fibonacci Generators•xn = (xn-1 + xn-2) % m–Does not have good randomness properties–High serial correlation•An extension–xn = (xn-5 + xn-17) % 2k27Combined Generations•Add random numbers by two or more generators–Can considerably increase the period and randomnessxn = 40014xn-1 % 2147483563yn = 40692yn-1 % 2147483399wn = (xn - yn) % 2147483562–This generator has a period of 2.3 x 101828wn = 157wn-1 % 32363xn =


View Full Document

FSU CIS 5930r - Lecture 25 Random Number Generation

Download Lecture 25 Random Number Generation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 25 Random Number Generation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 25 Random Number Generation 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?