MATLAB Answers

How to generate unique random integers between 1 to n (with no possibility of Sequence)

2 views (last 30 days)
Farman Ullah
Farman Ullah on 11 Jun 2021
Commented: Farman Ullah on 11 Jun 2021
I have alread tryed randperm(5)
But unfortunately after try again and again at one stage it produced random numbers 1 2 3 4 5
how to resolve this problem.

Answers (2)

James Tursa
James Tursa on 11 Jun 2021
Edited: James Tursa on 11 Jun 2021
If 1:n is the only sequence you don't want, just use randperm(n) and reject the one case you don't want. I.e., if you get it then re-generate another case.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by