How to create non-repetitive random integers
31 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mohammad Monfared
il 23 Apr 2012
Commentato: Dmitry Kaplan
il 10 Ago 2021
Hi,
As the title suggests I want to create non-repetitive random integers but don't know how to... say 70 integers ranging from 1 to 100. is there a straight way to do this?
thanks,
0 Commenti
Risposta accettata
Grzegorz Knor
il 23 Apr 2012
Try this code:
N = 100;
x = randperm(N);
x = x(1:70)
2 Commenti
Dmitry Kaplan
il 10 Ago 2021
Another possibility (perhaps a little faster)
[~,idx]=sort(rand(100,1));
idx(1:70)
Più risposte (2)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!