private int pickGene(){
  double selector=Math.abs(random.nextDouble()) % fitnessSum;
  int j=0;
  double count=fitnesses[j];
  while (count < selector && j < fitnesses.length - 1) {
    count+=fitnesses[++j];
  }
  return j;
}

private int pickGene ( ) { double selector = Math . abs ( random . nextDouble ( ) ) % fitnessSum ; int j = 0 ; double count = fitnesses [ j ] ; while ( count < selector && j < fitnesses . length - 1 ) { count += fitnesses [ ++ j ] ; } return j ; }
picking a gene works like a roulette wheel : a random nummer between 0 and the total population fitness is chosen . then starting from the first index , the fitnesses of the genes are being added up sequentially , until the sum is greater than the chosen number . the index for the last gene is the pick . by this algorithm , the probability for a gene to be picked is proportional to it ' s fitness .
