Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy1no!pd7cy2no!shaw.ca!pd7urf1no.POSTED!53ab2750!not-for-mail
X-Trace-PostClient-IP: 24.79.146.116
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: recovering the jth state of the random number generator
References: <g9sh0d$pra$1@fred.mathworks.com>
In-Reply-To: <g9sh0d$pra$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 34
Message-ID: <MCkwk.148759$nD.29247@pd7urf1no>
Date: Sat, 06 Sep 2008 01:00:28 GMT
NNTP-Posting-Host: 24.66.94.143
X-Complaints-To: abuse@shaw.ca
X-Trace: pd7urf1no 1220662828 24.66.94.143 (Fri, 05 Sep 2008 19:00:28 MDT)
NNTP-Posting-Date: Fri, 05 Sep 2008 19:00:28 MDT
Bytes: 2837
X-Original-Bytes: 2794
Xref: news.mathworks.com comp.soft-sys.matlab:488881



Tudor wrote:

> I find that if i run the iteration above repeatedly, to any given point 
> ( say 43001) i get back the same randomnoise matrix as expected, however if i   ask for 
> rand ('state', 43001)
> randmonoisematrix = rand (45, 45) i get a completely different output.  
> I other words, it appears that the state 0 is not followed by the state 1, 2, 3 etc.

Correct. The state is used to initialize the internal binary data used in
the pseudo-random number generator. The state is not a counter of how many
values have been produced.

> The reason i want to do this is because i do not want to have to run each time
> through the whole sequence to get to my epoch of interest, but rather would like
> to "skip" ahead to the state i want (inbetween 43000 and 43060 for example).

You will have to create your own random number generator then. For example, you
could MD5 the state number, extract some bits from the MD5 and typecast() the
result to a floating point number.

Or you could research one of the linear congruential pseudo random number generators.
Although they are usually processed sequentially, if you go back to the theory
of them, you could go directly to any particular state without a lot more work
than raising a large number to a power (the state number) modulo a large number.
You would have to use indefinite precision arithmetic to do it the naive way as
the values get *huge*, but fortunately you can take advantage of the fact that
the number and the modulus will be relatively prime (for any PRNG of maximum
length) and there are theorems that in that case allow the work to be done to
be reduced enormously (to a practical level, if you have the right software.)

-- 
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end