Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Created July 15, 2022 10:49
Show Gist options
  • Save LiorB-D/9af86b259404172ad07fa1a6feb84e66 to your computer and use it in GitHub Desktop.
Save LiorB-D/9af86b259404172ad07fa1a6feb84e66 to your computer and use it in GitHub Desktop.
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