CPE 619 Random-Number GenerationOverviewRandom-Number GenerationA Sample GeneratorTerminologyDesired Properties of a Good GeneratorTypes of Random-number GeneratorsLinear-Congruential GeneratorsLinear-Congruential Generators (cont’d)Selection of LCG ParametersSelection of LCG Parameters (cont’d)Period vs. AutocorrelationMultiplicative LCGMultiplicative LCG with m=2kExample 26.1aExample 26.1bMultiplicative LCG with m¹2kExample 26.2Schrage's MethodExample 26.3Generator Using Integer ArithmeticGenerator Using Real ArithmeticTausworthe GeneratorsTausworthe Generators (cont’d)Example 26.4Example 26.4 (cont’d)Combined GeneratorsCombined Generators (cont’d)Slide 43Slide 44Survey of Random-Number GeneratorsSurvey of RNG’s (cont’d)Slide 47Survey of RNG’s (Cont)Slide 49Seed SelectionSeed Selection (cont’d)Table of SeedsMyths About Random-Number GenerationMyths (cont’d)Slide 55Example 26.7Example 26.7 (cont’d)SummaryCPE 619Random-Number GenerationAleksandar MilenkovićThe LaCASA LaboratoryElectrical and Computer Engineering DepartmentThe University of Alabama in Huntsvillehttp://www.ece.uah.edu/~milenkahttp://www.ece.uah.edu/~lacasa2OverviewDesired properties of a good generatorLinear-congruential generatorsTausworthe generatorsSurvey of random number generatorsSeed selectionMyths about random number generation3Random-Number GenerationRandom Number = Uniform(0, 1)Random Variate = Other distributions = Function(Random number)4A Sample GeneratorFor example,Starting with x0=5:The first 32 numbers obtained by the above procedure 10, 3, 0, 1, 6, 15, 12, 13, 2, 11, 8, 9, 14, 7, 4, 5; 10, 3, 0, 1, 6, 15, 12, 13, 2, 11, 8, 9, 14, 7, 4, 5. By dividing x's by 16:0.6250, 0.1875, 0.0000, 0.0625, 0.3750, 0.9375, 0.7500, 0.8125, 0.1250, 0.6875, 0.5000, 0.5625, 0.8750, 0.4375, 0.2500, 0.3125; 0.6250, 0.1875, 0.0000, 0.0625, 0.3750, 0.9375, 0.7500, 0.8125, 0.1250, 0.6875, 0.5000, 0.5625, 0.8750, 0.4375, 0.2500, 0.3125.5TerminologySeed = x0 Pseudo-Random: Deterministic yet would pass randomness testsGenerator function is known (preferred in simulations)Fully Random: Not repeatable Cycle length, Tail, PeriodGoal: Select appropriate generator function and appropriate value for seed6Desired Properties of a Good GeneratorIt should be efficiently computableRepeated many times during a simulationThe period should be largeTo benefit from possibly long simulationsThe successive values should be independent and uniformly distributed The correlation between successive numbers should be small (discussed in Chapter 27)7Types of Random-number GeneratorsLinear congruential generatorsTausworthe generatorsExtended Fibonacci generatorsCombined generators8Linear-Congruential GeneratorsDiscovered by D. H. Lehmer in 1951The residues of successive powers of a number have good randomness propertiesEquivalently,a = multiplierm = modulus9 Linear-Congruential Generators (cont’d)Lehmer's choices: a=23 and m=108+1Good for ENIAC, an 8-digit decimal machine Generalization:Can be analyzed easily using the theory of congruences Mixed Linear-Congruential Generators or Linear-Congruential Generators (LCG)Mixed = both multiplication by a and addition of b10Selection of LCG ParametersChoice of a, b, and m affect the period and autocorrelation 1) The modulus m should be largeAll x’s are between 0 and m-1,the period can never be more than m2) For mod m computation to be efficient, m should be a power of 2 Mod m can be obtained by truncation11Selection of LCG Parameters (cont’d)3) If b is nonzero, the maximum possible period m is obtained if and only if:Integers m and b are relatively prime, that is, have no common factors other than 1Every prime number that is a factor of m is also a factor of a-1If integer m is a multiple of 4, a-1 should be a multiple of 4Notice that all of these conditions are met if m=2k, a = 4c + 1, and b is oddHere, c, b, and k are positive integers12Period vs. AutocorrelationA generator that has the maximum possible period is called a full-period generatorLower autocorrelations between successive numbers are preferable Both generators have the same full period, but the first one has a correlation of 0.25 between xn-1 and xn, whereas the second one has a negligible correlation of less than 2-1813Multiplicative LCGMultiplicative LCG: b=0Two types:m = 2km 2k14Multiplicative LCG with m=2km = 2ktrivial divisionMaximum possible period 2k-2Period achieved if multiplier a is of the form 8i3, and the initial seed is an odd integerOne-fourth the maximum possible may not be too smallLow order bits of random numbers obtained using multiplicative LCG's with m=2k have a cyclic pattern15Example 26.1aUsing a seed of x0=15, 25, 29, 17, 21, 9, 13, 1, 5,…Period = 8 = 32/4With x0=2, the sequence is 10, 18, 26, 2, 10, …Here, the period is only 416Example 26.1bMultiplier not of the form 8i 3:Using a seed of x0=1, we get the sequence 7, 17, 23, 1, 7,…The period is only 417Multiplicative LCG with m2kModulus m = prime numberWith a proper multiplier a, period = m-1Maximum possible period = mIf and only if the multiplier a is a primitive root of the modulus m a is a primitive root of m if and only if an mod m 1 for n = 1, 2, …, m-218Example 26.2Starting with a seed of x0=11, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28, 22, 4, 12, 5, 15, 14, 11, 2, 6, 18, 23, 7, 21, 1, …The period is 303 is a primitive root of 31 With a multiplier of a = 5 1, 5, 25, 1,…The period is only 3 5 is not a primitive root of 31Primitive roots of 31= 3, 11, 12, 13, 17, 21, 22, and 2419Schrage's MethodPRN computation assumes: No round-off errors, integer arithmetic, and no overflowsRound-off errors: if computation is done using real numbers Can't do it in BASICProduct a xn-1 > Largest integerOverflow => Use Scharge’s methodIdentity: Where:And:Here, q = m div a, r = m mod a`A div B' = dividing A by B and truncating the resultFor all x's in the range 1, 2, …, m-1, computing g(x) involves numbers less than m-1If r < q, h(x) is either 0 or 1, and it can be inferred from g(x);h(x) is 1 if and only if g(x) is negative20Example 26.3231-1 = 2147483647 = prime number 75 =
View Full Document