Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Multiple independent random number streams cannot be implemented.
Replies: 6   Last Post: Mar 19, 2013 1:51 AM

 Messages: [ Previous | Next ]
 David Bailey Posts: 714 Registered: 11/7/08
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

Date Subject Author
3/15/13 Sseziwa Mukasa
3/17/13 David Bailey
3/18/13 Vince Virgilio
3/19/13 David Bailey
3/19/13 Vince Virgilio
3/16/13 waku