Skip to content

Instantly share code, notes, and snippets.

@NicolleLouis
Last active March 12, 2019 17:38
Show Gist options
  • Save NicolleLouis/0fd7f0cefb4903ac37e7d47eef9f927e to your computer and use it in GitHub Desktop.
Save NicolleLouis/0fd7f0cefb4903ac37e7d47eef9f927e to your computer and use it in GitHub Desktop.
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
@AngeloGiacco
Copy link

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