
Re: Multiple independent random number streams cannot be implemented.
Posted:
Mar 17, 2013 7:48 PM


On 15/03/2013 05:46, Sseziwa Mukasa wrote: > You are asking for the opposite of independent random variables. > > I can think of a couple of solutions to your problem. If you know how > many samples you're going to take you can initialize a vector and have f > & g remember where they are in the vector. > There is a variable called $RandomState, which is poorly documented, but seems (from a quick test) to hold enough information to restore the random number generator to any position. Thus, any process can generate its own random sequence:
fstate = 0; f[] := Block[{$RandomState = $RandomState, tmp}, If[fstate ===0, SeedRandom["The f function"]; fstate = $RandomState; ]; $RandomState = fstate; tmp = Random[]; fstate = $RandomState; tmp ]; gstate = 0; g[] := Block[{$RandomState = $RandomState}, If[gstate ===0, SeedRandom["The g function"]; gstate = $RandomState; ]; $RandomState = gstate; tmp = Random[]; gstate = $RandomState; tmp ]
Unfortunately, the documentation at 9.0 deprecates the use of $RandomState  stating that it is superseded by BlockRandom  but clearly $RandomState can solve problems which BlockRandom cannot.
David Bailey http://www.dbaileyconsultancy.co.uk

