Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <iaq1os$sak$1@fred.mathworks.com> <iarp4o$d46$1@fred.mathworks.com> <iat4cg$cpi$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1288851604 10398 172.30.248.35 (4 Nov 2010 06:20:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 4 Nov 2010 06:20:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com 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);  
a(loc)=[];

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.

Bruno