class StochasticUniversalSamplingSelectionOperator extends FitnessProportionateSelectionOperator {

    @Override
    protected List<Individual> selectWinners(Individual[] inputIndividuals, double[] accumulatedProbabilities) {
        int resultSize = this.outputArity * this.individualsPerPopulation;
        List<Individual> resultingIndividuals = new ArrayList<Individual>(resultSize);
        double stepSize = 1.0 / resultSize;
        double fraction = this.randomGenerator.nextDouble(0.0, stepSize);
        int probabilitiesIndex = 0;
        for (int currentStep = 0; currentStep < resultSize; currentStep++){
            double currentProbability = stepSize * currentStep + fraction;
            // select first individual which accumulated probability is bigger or equal to currentProbability
            while (true){
                if (accumulatedProbabilities[probabilitiesIndex] >= currentProbability){
                    resultingIndividuals.add(inputIndividuals[probabilitiesIndex]);
                    break;
                } else {
                    probabilitiesIndex++; // increase only if not selected - to prevent bad behaviour when Individuals probability overlaps more than one interval
                }
            }
        }
        return resultingIndividuals;
    }

}