```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to generate random variable with constraint?
Date: Tue, 20 Jul 2010 19:06:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <i24s3b\$58o\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1279652779 5400 172.30.248.37 (20 Jul 2010 19:06:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 20 Jul 2010 19:06:19 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:654691

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i24pio\$k5f\$1@fred.mathworks.com>...
>
> A=cumsum(rand(1,6)); A=A/A(end); A(end)=[];
>
> I reran John's 2D test on this and find that it covers the correct triangular area, though slightly less uniformly than the sorting method.
>
> Again, though, for me, this was all just an exercise in seeing if we could get something nearly as good using cheaper summations instead of sorting.
- - - - - - - - - - -
Matt I checked out the two-dimensional plot for your revised code:

A=cumsum(rand(1,6)); A=A/A(end); A(end)=[];

It does cover the correct triangle.  However it is grossly inaccurate to say that it is only "slightly less uniform than the sorting method."  The probability area density actually drops down to zero at each corner of that triangle, whereas in a good solution it ought to be a uniform plateau throughout the entire triangle's area.  This disparity would continue to worsen as the number of variables increases, though unfortunately it is difficult to illustrate this fact with plots.

Roger Stafford
```