How to create non-repetitive random integers
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohammad Monfared
am 23 Apr. 2012
Kommentiert: Dmitry Kaplan
am 10 Aug. 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 Kommentare
Akzeptierte Antwort
Grzegorz Knor
am 23 Apr. 2012
Try this code:
N = 100;
x = randperm(N);
x = x(1:70)
2 Kommentare
Dmitry Kaplan
am 10 Aug. 2021
Another possibility (perhaps a little faster)
[~,idx]=sort(rand(100,1));
idx(1:70)
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!