Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 712
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;
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





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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.