Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Created July 15, 2022 10:49
function selectRandParent(tFit) {
let randVal = tFit * random() // Random value between (0, tFit)
let count = 0 // Cumulitive Fitness
for(let i = 0; i < cars.length; i++) {
count += cars[i].fitness
if(randVal <= count) {
return i
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment