From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Randomly permute a given set of numbers
Date: Sun, 12 Sep 2010 18:22:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 10
Message-ID: <i6j5ob$i4i$>
References: <i6hq95$fjn$> <i6hsgb$3oh$> <i6hu32$cb$> <i6hv12$d5r$> <i6i3n3$fff$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1284315723 18578 (12 Sep 2010 18:22:03 GMT)
NNTP-Posting-Date: Sun, 12 Sep 2010 18:22:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:669408

  Venkatesh didn't make it clear what relative frequencies are desired for the different nonzero row counts.  If each count is assumed to have an equal probability, one could simply do this:

 A = zeros(n,m);
 for k = 1:n
  p = randperm(m);
  q = 1:floor((m-1)*rand+2);
  A(k,p(q)) = q;

Roger Stafford