Select a random number from a set
93 ビュー (過去 30 日間)
古いコメントを表示
I'm simulating a single blackjack hand and am trying to "draw" a card. I can't use the randi function because I don't want all possibilities to have the same probability of being selected. So what I have done is created a row vector , (x), of all the possible card values. Now I would like draw a random number from this selection for my 'draw' function. Thanks for the help!
x = [1,2,3,4,5,6,7,9,10,10,10,10,11] theCard = randi?
5 件のコメント
Walter Roberson
2021 年 1 月 8 日
T1 = randperm(9)
reshape(T1, 3, 3)
T2 = randperm(9)
reshape(T2, 3, 3)
You can see that the randperm(9) call is picking values randomly, and the reshape is making a 3 x 3 out of it.
Or perhaps you mean that you have created an existing 3 x 3 matrix and you want to take a random value out of it?
T3 = [11 12 13
21 22 23
31 32 33]
T3(randi(numel(T3)))
T3(randi(numel(T3)))
回答 (2 件)
Lucas García
2011 年 11 月 8 日
There are a few ways to do it. For example, using randi to select in which position is the card that you will extract.
pos = randi(length(x));
card = x(pos);
5 件のコメント
N/A
2019 年 1 月 29 日
here is a way to do it :
for i = 1:5
arrayA(i) = randi(length(A));
arrayB(i) = randi(length(B));
end
Vineeth Krishnan
2020 年 12 月 11 日
for i=1:5
arrayA(i) = A(randi(length(A));
arrayB(i)= B(randi(length(B));
end
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!