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