code: protected void doReplacement(List<EvaluatedCandidate<T>> existingPopulation,
                                   List<EvaluatedCandidate<T>> newCandidates,
                                   int eliteCount,
                                   Random rng)
      {
          assert newCandidates.size() < existingPopulation.size() - eliteCount : "Too many new candidates for replacement.";
          // If this is strictly steady-state (only one updated individual per iteration), then we can't keep multiple
          // evolved individuals, so just pick one at random and use that.
          if (newCandidates.size() > 1 && forceSingleCandidateUpdate)
          {
              // Replace a randomly selected individual, but not one of the "elite" individuals at the
              // beginning of the sorted population.
              existingPopulation.set(rng.nextInt(existingPopulation.size() - eliteCount) + eliteCount,
                                     newCandidates.get(rng.nextInt(newCandidates.size())));
          }
          else
          {
              for (EvaluatedCandidate<T> candidate : newCandidates)
              {
                  // Replace a randomly selected individual, but not one of the "elite" individuals at the
                  // beginning of the sorted population.
                  existingPopulation.set(rng.nextInt(existingPopulation.size() - eliteCount) + eliteCount, candidate);
              }
          }
      }
docs: Add the offspring to the population, removing the same number of existing individuals to make
  space for them.
  This method randomly chooses which individuals should be replaced, but it can be over-ridden
  in sub-classes if alternative behaviour is required.
  @param existingPopulation The full popultation, sorted in descending order of fitness.
  @param newCandidates The (unsorted) newly-created individual(s) that should replace existing members
  of the population.
  @param eliteCount The number of the fittest individuals that should be exempt from being replaced.
  @param rng A source of randomness.