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

7 Ansichten (letzte 30 Tage)
Vincent
Vincent am 25 Sep. 2022
Beantwortet: Steven Lord am 25 Sep. 2022
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 Kommentare
Vincent
Vincent am 25 Sep. 2022
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.
Vincent
Vincent am 25 Sep. 2022
Nevermind Im an idiot

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 25 Sep. 2022
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.

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by