Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: array with random not repeated numbers
Date: Tue, 7 Jun 2011 01:16:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <isju4k\$6ok\$1@newscl01ah.mathworks.com>
References: <hdco0i\$1kk\$1@fred.mathworks.com> <isjc8p\$j7j\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1307409364 6932 172.30.248.46 (7 Jun 2011 01:16:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 7 Jun 2011 01:16:04 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:730541

"Derek O'Connor" wrote in message <isjc8p\$j7j\$1@newscl01ah.mathworks.com>...
> See this thread:
>
>
> Derek O'Connor
- - - - - - - - - - -
Thanks for reminding us of that thread, Derek.  I had completely forgotten about that interesting discussion.

This is an alternate method for choosing n non-repeating random integers out of [min:max] that avoids 'randperm' and its sorting:

p = min:max;
m = length(p);
r = zeros(1,n);
for k = m:-1:m-n+1
q = ceil(k*rand);
r((m+1)-k) = p(q); % <-- n random integers go to 'r'
p(q) = p(k);
end

This method might be preferable in cases where max-min is so large as to require excessive time be spent sorting in 'randperm'.

Roger Stafford