How to draw (random or with certain chance) multiple elements from a set where the element must not be equal to each other
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Andrei Bobrov
2017년 6월 6일
V = [1 2 3 4 5 6];
A = nchoosek(V,3);
strategies = A(randperm(size(A,1),10),:);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!