MATLAB: No repetition in the result of a roulette wheel selection function

genetic algorithmrandom number generator

Please, I would like to ask someone a little question: what should I do if I have to write a roulette selection function for a genetic algorithm in which the resulting numbers have no repetition. In example, if I write the selectionroulette of matlab toolbox:
function parents = selection3roulette(expectation,nParents,options)
% example
nParents=14;
expectation=[1.6098;
0.9294;
1.1383;
1.9716;
1.3941;
1.2470;
0.9858;
0.8817;
1.0539;
2.7883];
expectation = expectation(:,1);
wheel = cumsum(expectation) / nParents;
parents = zeros(1,nParents);
for i = 1:nParents
r = rand;
for j = 1:length(wheel)
if(r < wheel(j))
parents(i) = j;
break;
end
end
end
disp('parents=');disp(parents);
at the end I could obtain : parents= [5 5 1 5 7 6 2 7 5 8 1 5 3 8] instead I wolud have different elements into the array… Thank you very much….

Best Answer

doc randperm
maybe?