Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13842

Re: Multiple independent random number streams cannot be implemented.

Path csiph.com!usenet.pasdenom.info!goblin1!goblin.stu.neva.ru!uio.no!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Vince Virgilio <blueschi@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Multiple independent random number streams cannot be implemented.
Date Fri, 15 Mar 2013 05:46:05 +0000 (UTC)
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <khucit$85$1@smc.vnet.net> (permalink)
References <khsbbv$36f$1@smc.vnet.net>
Lines 58
Organization Time-Warner Telecom
NNTP-Posting-Date 15 Mar 2013 05:46:24 GMT
NNTP-Posting-Host 5230cf18.news.twtelecom.net
X-Trace DXC=]fV6U5dZQD=nDA28:Ahki0C_A=>8kQj6=9BHNOcEA\@9khPHh98B@E9EFiONJ7[Go6Wimlk7Nd8f5
X-Complaints-To abuse@twtelecom.net
Xref csiph.com comp.soft-sys.math.mathematica:13842

Show key headers only | View raw


It is possible, but I found it requires a couple of layers of abstraction. 
(Perhaps there's an easier way.)

Basically, wrap calls to RandomReal[] etc. with something that can hold persistent state. On each call, SeedRandom[lastState], then lastState = Random`GetRandomState[]. The body looks something like this:

    method[Hold[e__] ] := BlockRandom[SeedRandom@lastState;
        With[{result = e}, lastState = Random`GetRandomState[]; result]];

(Implementation of <object>`method not shown. It uses my own flyweight OO framework.)

This has allowed me to run an arbitrary number of unique and reproducible random # streams.

Sorry that there's no time for more detail now.

Vince

On Thursday, March 14, 2013 7:13:03 AM UTC-4, Roger Wilson wrote:
> Hopefully the title is enough of a red flag for someone to try to prove me wrong.
>
>
>
> I want to implement two functions; lets call them f and g so that they both return random numbers.  For example...
>
>
>
> f[]:=RandomReal[];
>
> g[]:=RandomReal[];
>
>
>
> However I want f and g to return the same number when they're called for the nth time.  So the first call to f is always the same number and the first call to g is always the same number.
>
>
>
> In the above case (on my machine)...
>
> SeedRandom[1]; {f[], g[]} gives {0.168697, 0.113119}
>
>
>
> and of course..
>
> SeedRandom[1]; {g[], f[]} gives the same {0.817389, 0.11142}
>
>
>
> Essentially I want f and g to to be independent random sources.
>
>
>
> It is possible to localize the random number generators using BlockRandom but I do not see how that helps me in this case.  BlockRandom localizes the state of the random number generators within the block where as I want to localize them into the symbol names.
>
>
>
> Roger

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Multiple independent random number streams cannot be implemented. Roger Wilson <rogerhw999@gmail.com> - 2013-03-14 11:13 +0000
  Re: Multiple independent random number streams cannot be implemented. Vince Virgilio <blueschi@gmail.com> - 2013-03-15 05:46 +0000
  Re: Multiple independent random number streams cannot be implemented. Joe Gwinn <joegwinn@comcast.net> - 2013-03-15 05:46 +0000
  Re: Multiple independent random number streams cannot be implemented. Roger Wilson <rogerhw999@gmail.com> - 2013-03-16 07:13 +0000

csiph-web