Select a random number from a set

조회 수: 298(최근 30일)
Matt Medley
Matt Medley 2011년 11월 8일
답변: Souarv De 2021년 6월 8일
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
Nour Ahmed
Nour Ahmed 2021년 1월 9일
Yesss thankk youuu

댓글을 달려면 로그인하십시오.


Lucas García
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
Vineeth Krishnan
Vineeth Krishnan 2020년 12월 11일
for i=1:5
arrayA(i) = A(randi(length(A));
arrayB(i)= B(randi(length(B));

댓글을 달려면 로그인하십시오.

Souarv De
Souarv De 2021년 6월 8일
rand_Pos = randperm(length(x),1)
card = x(rand_Pos)


Find more on Creating and Concatenating Matrices 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!

Translated by