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

3 vues (au cours des 30 derniers jours)
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

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by