Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Multiple independent random number streams cannot be implemented.
Posted:
Mar 16, 2013 3:13 AM


On Thursday, 14 March 2013 11:13:03 UTC, 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
I'm replying to myself as several people have been kind enough to post replies here and to me directly. I'll try to describe the problem in more detail. I should point out that I've worked around the issue using BlockRandom so its not longer a problem, just academic interest now.
The problem is a montecarlo simulation involving Brownian Bridges. I have a paths which are sequences of random numbers. I start of with one number , subdivide it into two with the Brownian bridge, subdivide that into 4 etc. Each subdivision pulls more random numbers from the RNG. One set of paths stating with the coarsest path to the finest path (say divided into 64 steps) is one montecarlo sample.
If I need 1000 samples I generate each the first set of subdivided paths, then the second then third etc generating paths of lengths 1,2,4,8,16,32&64. A problem arises if I change the depth of the subdivision. Say I only subdivided the paths into 1,2,4,8,16&32 sections not but not 64. With the same random seed, the first sample (with paths lengths 1,2,4,8,16&32) will be the same (except missing the finest layer) but the next sample will be completely different because its now consuming random variates from the RNG which would have been used to refine the finest layer of the sample before.
A solution to this would have been to use a separate RNG for each subdivision layer, saving and restoring $RandomState indexed on the layers depth. That way the random numbers used for say, layer three would be independent of the simulation having a layer 7 or not.
However $RandomState is a legacy feature and in v.9 does not change at all as the random numbers are generate (except in Legacy mode). BlockRandom is the replacement but requires a change of paradigm.
My solution has been to generate each sample of subdivided path inside a BlockRandom with its own seed (randomly generated outside the BlockRandom). This then means that each sample will generate the same coarser paths independently of the finer paths being generated. The sequence of seeds for each sample generation can be seeded itself using SeedRandom (its outside the BlockRandom used to isolate the sample generation).
Many thanks for everyone's replies but there are too many to respond to individually.
Roger



