Generating a Random Number from an array for a blackjack simulator-Matlab

Click For Summary
To generate a random card for a blackjack simulator in MATLAB, the user is attempting to draw from an array of possible card values. The current code uses the `randi` function incorrectly, as it is designed for generating random integers within a specified range, not for selecting from an array. Instead, the user should use the `randi` function to determine an index for the array and then retrieve the card value from that index. The correct approach would be to use `x(randi(length(x)))` to get a random card from the defined array. This method will effectively solve the problem of drawing a random card for the blackjack game.
Matt12
Messages
2
Reaction score
0
Generating a Random Number from an array for a blackjack simulator--Matlab

I have a homework problem where I have to generate a single hand of blackjack to a player and allow the player to hit or hold. I'm ahving trouble generating the random card.

My attempt:

x = [1,2,3,4,5,6,7,8,9,10,10,10,10,11]; %the possible random numbers
CardValue = randi(x,1) %this is the problem, I want to draw a random card from the array



Thanks for any help!
 
Physics news on Phys.org


Also, this is my first post so if I'm in the wrong category or need to tell more, let me know!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
7K
  • · Replies 21 ·
Replies
21
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
25
Views
4K