How to draw (random or with certain chance) multiple elements from a set where the element must not be equal to each other

3 views (last 30 days)
n = 10
m = 3
strategies = zeros(n,m)
V = [1 2 3 4 5 6]
I want to draw m numbers from V n times, where strategies(i,1) strategies(i,2) and strategies(i,3) may NOT be equal so a good solution for example strategies(i,:) = [1 6 4] bad solution = strategies(i,:) = [1 6 1] (cause there are two ones
pseudo code:
for i = 1:n
for j = 1:m
strategies(i,j) = random(V)
strategies(i,1) isnot strategies(i,2) isnot strategies(i,3)
end
end
good answer would be
1 3 4
4 5 6
6 1 3
3 5 6
2 1 4
etcccc
I Hope somebody can help me! (and sorry for bad englisch)
extra: if somebody know how to draw with a certain chance each element of V that would be awesome to

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 6 Jun 2017
V = [1 2 3 4 5 6];
A = nchoosek(V,3);
strategies = A(randperm(size(A,1),10),:);

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!