Last active
March 12, 2019 17:38
-
-
Save NicolleLouis/0fd7f0cefb4903ac37e7d47eef9f927e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def createChild(individual1, individual2): | |
child = "" | |
for i in range(len(individual1)): | |
if (int(100 * random.random()) < 50): | |
child += individual1[i] | |
else: | |
child += individual2[i] | |
return child | |
def createChildren(breeders, number_of_child): | |
nextPopulation = [] | |
for i in range(len(breeders)/2): | |
for j in range(number_of_child): | |
nextPopulation.append(createChild(breeders[i], breeders[len(breeders) -1 -i])) | |
return nextPopulation |
If you follow the code in passwordTuto from his profile then by design all individuals in the population will have the same length as the desired password. Also, all children will have the same length so there is no need to account for differences in length as there simply will not be.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does createChild() account for the possibility that the length of individual1 is greater than that of individual2? It looks like that scenario would produce an out of range error.