Path: news.mathworks.com!not-for-mail
From: "Derek O'Connor" <derekroconnor@eircom.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Random Integers Within Specfic Ranges
Date: Sat, 12 Mar 2011 17:36:04 +0000 (UTC)
Organization: University College Dublin
Lines: 22
Message-ID: <ilgau4$5hb$1@fred.mathworks.com>
References: <ildgd8$dhl$1@fred.mathworks.com> <ilfv5b$6pa$1@fred.mathworks.com> <ilg1cg$r6q$1@fred.mathworks.com>
Reply-To: "Derek O'Connor" <derekroconnor@eircom.net>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1299951364 5675 172.30.248.48 (12 Mar 2011 17:36:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 12 Mar 2011 17:36:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 87230
Xref: news.mathworks.com comp.soft-sys.matlab:715402

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ilg1cg$r6q$1@fred.mathworks.com>...
> "Derek O'Connor" wrote in message <ilfv5b$6pa$1@fred.mathworks.com>...
> 
> > 
> > If m is approx. equal to n then this method is optimal. If m is much smaller than n then there are two obvious inefficiencies: (1) a vector p of size n is used, and (2) the for-loop takes n-1 steps.
> > 
> 
> Storing full p seems to be unavoidable in Roger's method.
> The point (2) is not a point, just iterate m time then stop.
> 
> Bruno

Bruno,

Point (2) is a point. 

for k = 2:m does not work. Note the first statement in the for k-loop: r = ceil(rand*k);

For example let L = -50, U = 50, and m = 3. This means that only the first 3 elements of p = [-50 -49 -48 -47 .. 59 50] get shuffled and we get p = [p1 p2 p3 -47..50]. Thus a random sample of the numbers -50, -49, -48 is returned instead of something such as 
-42 39 -29 which is one of the samples which GRPfysLUM(-50,50,3) returns.

Derek O'Connor.