Skip to main content
. 2022 Jan 27;14(3):512. doi: 10.3390/polym14030512
%% This function creates Roulette Wheel Selection
function choice = RouletteWheelSelection(weights)
    accumulation = cumsum(weights);
    p = rand() * accumulation(end);
    chosen_index = −1;
    for index = 1:length(accumulation)
        if (accumulation(index) > p)
            chosen_index = index;
            break;
        end
      end
      choice = chosen_index;