Generate random integer array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bill Symolon
le 25 Jan 2017
Réponse apportée : Image Analyst
le 25 Jan 2017
I need to create an array of random integers. The array must consist of at least two numbers greater than one but there is no maximum array length. The elements of the array need to sum to less than 46. Thanks for your help.
5 commentaires
John D'Errico
le 25 Jan 2017
Bill -
If you know n in advance, then this is pertinent information, although still insufficient. n is not simply random. It is arbitrary, but known.
What do you do when n is 16? You need to explain these things, otherwise, one is forced to guess what you want to do.
So can we assume that n is given by the user. Then you want to come up with the number of cards in each pile, that then sums to n? Must each number be greater than 2? How large can any single pile of cards then be?
Réponse acceptée
Image Analyst
le 25 Jan 2017
I was about the say the same thing as Steven. Because it's card dealing, you need to use randperm(), not randi(). See my two attached car dealing demos.
0 commentaires
Plus de réponses (1)
Steven Lord
le 25 Jan 2017
If you're looking to shuffle a deck of cards, use randperm. Once you have a vector representing the shuffled deck of cards, use indexing to extract subsets of the vector to represent each of your piles.
0 commentaires
Voir également
Catégories
En savoir plus sur Random Number Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!