MATLAB Answers

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

조회 수: 2(최근 30일)
Farman Ullah
Farman Ullah 2021년 6월 11일
댓글: Farman Ullah 2021년 6월 11일
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.

답변(2개)


James Tursa
James Tursa 2021년 6월 11일
편집: James Tursa 2021년 6월 11일
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.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by