필터 지우기
필터 지우기

How to create non-repetitive random integers

조회 수: 31 (최근 30일)
Mohammad Monfared
Mohammad Monfared 2012년 4월 23일
댓글: Dmitry Kaplan 2021년 8월 10일
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,

채택된 답변

Grzegorz Knor
Grzegorz Knor 2012년 4월 23일
Try this code:
N = 100;
x = randperm(N);
x = x(1:70)
  댓글 수: 2
Mohammad Monfared
Mohammad Monfared 2012년 4월 23일
thanks, first time to see this nice function ;)
Dmitry Kaplan
Dmitry Kaplan 2021년 8월 10일
Another possibility (perhaps a little faster)
[~,idx]=sort(rand(100,1));
idx(1:70)

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

추가 답변 (2개)

Richard Brown
Richard Brown 2012년 4월 23일
randperm(100, 70)
  댓글 수: 2
Mohammad Monfared
Mohammad Monfared 2012년 4월 23일
thanks, I use matlab R2011a and the randperm doesn't accept two arguments.
Richard Brown
Richard Brown 2012년 4월 23일
ah yes, that came in at R2011b

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


Jan
Jan 2012년 4월 23일
And if you are in a hurry: FEX: Shuffle

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by