From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: k (3) Vectors of ones and zeros "combining" together
Date: Wed, 18 Jan 2012 13:02:08 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 13
Message-ID: <jf6fsg$8cu$>
References: <jf510f$nv5$> <jf51ot$q13$> <jf5309$a8$> <jf59tg$jbs$> <jf5b6o$n2p$> <jf5re5$9lp$> <jf5rpc$ah4$> <jf6duk$2gh$>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1326891728 8606 (18 Jan 2012 13:02:08 GMT)
NNTP-Posting-Date: Wed, 18 Jan 2012 13:02:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: comp.soft-sys.matlab:755033

"Roger Stafford" wrote in message <jf6duk$2gh$>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jf5rpc$ah4$>...
> > Can you elaborate Roger? It can't feel how the non-equal probability would be possible.
> - - - - - - - - - -
>   Hi Bruno.  Now I can say with certainty that the probabilities are _not_ equal.  In the case of N = 5, with the algorithm I used, randperm will select each of the 120 permutations with equal probability.  However there are only 60 permutations involving the first 3 elements.  A permutation (swap) between the last 2 elements does not affect the statistics of the ceil(3*rand(1,N-3)) action, so it would be equivalent to assume that we are using only the first three elements of randperm and taking the remaining 2 in ascending order.  For each of these 60 permutations then, there are 9 possible outcomes of ceil(3*rand(1,N-3)), of which 3 choose the same value and 6 choose different values.  That means of a total of 60*9 equally likely events, 60*3 will be distributed equally over 60 known partitions of the 1+1+3 type and 60*6 will be distributed equally over 90 known partitions of the 
> type.  This gives a 1/180 probability for each of the first type and 1/135 for each of the second type.  The sampling runs I made earlier did in fact indicate the correct probabilities.  QED 

I see. Thank Roger for showing the drawback.

Perhaps that analysis shows the way to fix the original algorithm.