From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Randperm, Randi, and Shuffle
Date: Thu, 4 Nov 2010 06:20:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 20
Message-ID: <iatjak$a4u$>
References: <iaq1os$sak$> <iarp4o$d46$> <iat4cg$cpi$>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1288851604 10398 (4 Nov 2010 06:20:04 GMT)
NNTP-Posting-Date: Thu, 4 Nov 2010 06:20:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: comp.soft-sys.matlab:683751

> But it is biased also, because the reply of UNIQUE is sorted. But lukily SHUFFLE works efficient here:

This is good remark. To get unbiased selection, here is a more complicated code that select random points after calling unique. (it's needed my file MAXK on FEX)

n = 1100*200*200;
m = 125e3;

a = ceil(n*rand(1,round(1.1*m)));
a = unique(a);
l = length(a);
i = rand(1,l);
[~, loc] = maxk(i, l-m);  

This add a marginal additional runtime.

When m << n, the probability of the event (l < m) is tiny (I'm too lazy to calculate that). My guess is it never happens in practice.