The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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;
gstate = 0;
g[] := Block[{$RandomState = $RandomState},
If[gstate ===0,
SeedRandom["The g function"];
gstate = $RandomState;
$RandomState = gstate;
tmp = Random[];
gstate = $RandomState;

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.