no repetition in the result of a roulette wheel selection function

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....

 Accepted Answer

doc randperm
maybe?

3 Comments

thank you very much, Sean
I'm trying with this command..but I think I'm doing something wrong...
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;
nran = randperm(nParents)
r=nran/nParents
for j = 1:length(wheel)
if(r < wheel(j))
parents(i) = j
break;
end
end
end
Anyway, thank you a lot!!!
perhaps r(i) in the while criterion?
r<wheel(i) means ALL r < wheel(i) is that what you want? or do you want a specific r?
(Sorry, no roulette expert - blackjack is where the fun is!)
thank you for your useful (and funny!!)answer..
Now I'm going to try with the while cycle...
Otherwise I'll turn to blackjack too :)

Sign in to comment.

More Answers (0)

Categories

Find more on Card games in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!