160 likes | 170 Views
Explore how Genetic Algorithms enhance Linear Congruential Generators, popular PRNGs with potential issues. Learn how fitness functions and statistical tests can improve LCG efficiency.
E N D
Genetic Algorithms Can Be Used To Obtain Good Linear Congruential Generators Presented by Ben Sproat
Outline • Linear Congruential Generators • What are they? • Why do we need a Genetic Algorithm? • Genetic Algorithm • What are they? • What do we need to use one? • Putting them together • How do we decide if we have a good LCG? • Results
Linear Congruential Generators • Currently one of the most popular Pseudorandom Number Generator • Proposed by Lehmer in 1948 • Xn+1 = (a * Xn + b) mod m where Xo=seed • Easy to implement and very fast
Simple LCG • a= 7, b=2, m=17, Xo=9 • X1= (7 * 9 +2) mod 17 = 14 • X2= (7 *14 +2) mod 17 = 15 • X3= (7 *15 +2) mod 17 = 5 • X4= (7 * 5 +2) mod 17 = 3 • X5= (7 * 3 +2) mod 17 = 6
Problems With LCG’s • Vulnerable to certain types of attacks • Should not be used as key generators • Given certain choices for a, b, and m the numbers it produces may not be very useful • Requires looking up good values for a, b, and m • Many programmers use pseudorandom techniques to pick a, b, and m
A bad LCG • a= 1, b=4, m=8, Xo=5 • X1= (1 * 5 +4) mod 8 = 1 • X2= (1 * 1 +4) mod 8 = 5 • X3= (1 * 5 +4) mod 8 = 1 • X4= (1 * 5 +4) mod 8 = 5 • X5= (1 * 3 +4) mod 8 = 1
Genetic Algorithms • Blind, stochastic near-optimal heuristic search method • Uses a fitness function to select potential chromosomes to be reproduced • Uses Genetic operators to reproduce • Uses a Convergence criteria to decide when to stop
Crossover and Mutation • Chromosome 1=1010 1110 • Chromosome 2=1100 0110 • Crossover Chromosome 1= 1010 0110 • Crossover Chromosome 2=1100 1110 • Mutant Chromosome 1=1011 1110 • Mutant Chromosome 2=1100 0100
The Genetic Algorithm • A population of N chromosomes is generated • N chromosomes are selected randomly using the fitness function to determine proportions • Two chromosomes are selected at random and crossed over and put in the new population repeat until the pool is empty • Mutate all the new Chromosomes • Test if the convergence criteria has been met • If not repeat
Fitness Functions For our Problem • There are many ways to determine a good LCG • May depend on what it will be used for • There is really no good way to determine if an LCG is good or bad, so a battery of tests is normally used
Statistical Tests For Randomness • Entropy: information density of the output of one cycle of the generator • Chi-Square percentile: no LCG passes this test • Arithmetic mean: the mean of the numbers generated should be approximately m/2 • Monte Carlo value for Pi: random numbers can be used to calculate Pi!
Statistical Tests For Randomness • Serial Correlation Coefficient: bit based dependency check • Maximal Period: The maximal period for an LCG is m • Percentage of the maximum period achieved:
Results • Fitness = entropy • Fitness = entropy + period • Fitness = entropy + period / maxperiod • Fitness = entropy * period / maxperiod
1: Per byte entropy (optimum = 8.0) 2: Chi-Square percentile 3: Arithmetic mean (optimum = 127.5) 4: Error % in the estimation of Pi
Conclusion • LCG’s are useful Pseudorandom Number Generators • You must be careful in selecting your LCG • Genetic Algorithms are a fast way of generating good LCG’s • A good fitness function is essential