Generating sets of non repeating random numbers
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Toluwani Adekunle
el 8 de Jul. de 2018
Comentada: Anton Semechko
el 9 de Jul. de 2018
Hi,
How do I create 10 sets of random numbers within a range such that after every set, the numbers previously generated can’t be repeated or generated again i.e if I generate [1,3,8,6] from the range [1:40] those numbers would be deleted from the range and can’t be generated again
0 comentarios
Respuesta aceptada
Más respuestas (1)
Anton Semechko
el 8 de Jul. de 2018
Here is an example:
S=reshape(randperm(40),[],4);
All elements in S will be in the range [1 40] and unique. From this it follows that all 10 rows of S will also be unique.
2 comentarios
Anton Semechko
el 9 de Jul. de 2018
Same idea applies, but cutoff the extraneous samples before reshaping. Example for 300 range and 27-by-9 matrix.
S=radndperm(300);
S=S(1:(27*9));
S=reshape(S,27,9);
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!