Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Randomly permute a given set of numbers
Date: Sun, 12 Sep 2010 08:41:07 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 11
Message-ID: <i6i3n3$fff$1@fred.mathworks.com>
References: <i6hq95$fjn$1@fred.mathworks.com> <i6hsgb$3oh$1@fred.mathworks.com> <i6hu32$cb$1@fred.mathworks.com> <i6hv12$d5r$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1284280867 15855 172.30.248.38 (12 Sep 2010 08:41:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 12 Sep 2010 08:41:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:669368

n=100; m=5;

[trash A] = sort(rand(n,m),2);
p = arrayfun(@(k) nchoosek(m,k), 2:m);
c = [0 cumsum(p)];
r = rand(size(A,1),1);
[trash i] = histc(r*c(end),c);
nz = i+1;
A = max(bsxfun(@minus,A,nz),0)

% Bruno