How do I pick a number from a set of random numbers?

4 次查看(过去 30 天)
I have generated numbers 1 through 52 in a random order. Next I have to pick a position and get what number is in that position but I cant do it.
What is a positive integer?
52
n =
52
p =
Columns 1 through 21
23 41 17 36 9 31 4 18 46 34 11 29 39 14 52 20 43 26 42 30 28
Columns 22 through 42
48 32 47 21 19 38 27 2 13 37 49 12 44 33 50 1 24 51 16 35 15
Columns 43 through 52
8 10 6 5 25 3 7 45 40 22
  4 个评论
Vincent
Vincent 2022-9-25
This was my teachers example:
For example, if the “deck” has N = 52 cards, the user might input v = 9, and the program might then reveal the 9th value in the shuffled deck to be 11.
And its supposed to be a positive integer 1 through 52.

请先登录,再进行评论。

回答(1 个)

Steven Lord
Steven Lord 2022-9-25
Since I suspect this is part of a homework assignment I'm not going to give you the answer, but I will point you toward two functions that may be of interest to you. Take a look at the documentation pages for randperm and randi. Which one you want to use will depend on whether you want to draw cards without replacement (randperm) like you're dealing out a poker hand or with replacement (randi) like if a stage magician asks you to draw a card, look at it, and return it to the deck.

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by