how can i build a function that can generate 5 random numbers
Mostrar comentarios más antiguos
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 comentarios
Paolo
el 29 de Mayo de 2018
mihaita98
el 29 de Mayo de 2018
Walter Roberson
el 29 de Mayo de 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 ?
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 29 de Mayo de 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 comentario
Image Analyst
el 29 de Mayo de 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.
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!