How to create non-repetitive random integers
30 views (last 30 days)
Show older comments
Mohammad Monfared
on 23 Apr 2012
Commented: Dmitry Kaplan
on 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 Comments
Accepted Answer
Grzegorz Knor
on 23 Apr 2012
Try this code:
N = 100;
x = randperm(N);
x = x(1:70)
2 Comments
Dmitry Kaplan
on 10 Aug 2021
Another possibility (perhaps a little faster)
[~,idx]=sort(rand(100,1));
idx(1:70)
More Answers (2)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!