how can i build a function that can generate 5 random numbers
Afficher commentaires plus anciens
is there a way to build a function() that once called, it will give in response 5 random numbers between 1 and 40, even if its a matrix?
3 commentaires
Paolo
le 29 Mai 2018
mihaita98
le 29 Mai 2018
Walter Roberson
le 29 Mai 2018
Are you wanting to iterate through all of the combinations of 40 items taken 5 at a time? There are 658008 of those. Or do you want all of the permutations of 40 items taken 5 at a time? There are 6799294027065814452880093913300965785600000000 of those.
When you say you want different numbers between consecutive calls, then do all of the numbers have to be different, or do you just not want the same list of numbers twice in a row? For example would [3 9 10 27 31] followed by [1 9 27 30 38] be acceptable ?
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 29 Mai 2018
If you just need to do this once then
randperm(40, 5)
If you need to create a number of these then there is a way using sort() but no direct call for it.
1 commentaire
Image Analyst
le 29 Mai 2018
Also to expand on that, randperm() gives random integer numbers without repeated numbers being possible. randi() will give random integers but repeats are possible.
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!