code: public <S> List<S> select(List<EvaluatedCandidate<S>> population,
                                boolean naturalFitnessScores,
                                int selectionSize,
                                Random rng)
      {
          List<S> selection = new ArrayList<S>(selectionSize);
  
          double ratio = selectionRatio.nextValue();
          assert ratio < 1 && ratio > 0 : "Selection ratio out-of-range: " + ratio;
          
          int eligibleCount = (int) Math.round(ratio * population.size());
          eligibleCount = eligibleCount > selectionSize ? selectionSize : eligibleCount;
  
          do
          {
              int count = Math.min(eligibleCount, selectionSize - selection.size());
              for (int i = 0; i < count; i++)
              {
                  selection.add(population.get(i).getCandidate());
              }
          } while (selection.size() < selectionSize);
          return selection;
      }
docs: Selects the fittest candidates.  If the selectionRatio results in
  fewer selected candidates than required, then these candidates are
  selected multiple times to make up the shortfall.
  @param population The population of evolved and evaluated candidates
  from which to select.
  @param naturalFitnessScores Whether higher fitness values represent fitter
  individuals or not.
  @param selectionSize The number of candidates to select from the
  evolved population.
  @param rng A source of randomness (not used by this selection
  implementation since truncation selection is deterministic).
  @param <S> The type of evolved entity that is being selected.
  @return The selected candidates.