Hi all,
I have the following function that generates random integers between two points:
Int = randi([x1 x2],1,10);
I am trying to find a neat way of generating these integers such that there is no repetition. i.e. I want 10 separate random integers in the answer. The difference between the values of x1 and x2 is large enough to generate separate integers; however, I do find that sometimes I get the same integer twice in the one solution. Any tips?

 채택된 답변

Star Strider
Star Strider 2017년 10월 18일

1 개 추천

One approach:
x1 = 5; % Create Limits
x2 = 15; % Create Limits
Out = (x1-1) + randperm(x2-x1+1, 10);

댓글 수: 2

Thank you this worked well
As always, my pleasure.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Design Optimization에 대해 자세히 알아보기

질문:

2017년 10월 18일

댓글:

2017년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by