About normal random number generator

Hi there,
I am running replicas of the same code on multiple machines and have found something strange. Although I clear everything and even reset the system clock (through rand('state',sum(100*clock));) but have found that DIFFERENT machines give the same result. I would have thought that the replication would happen on the same machine if it were. This has been the case with many runs. Any clue as to what might be going on and how could I mitigate the issue?
Thanks

回答(3 个)

TUSHAR ANDRIYAS
TUSHAR ANDRIYAS 2012-5-22
Forgot to add that I am running an Initial value problem on ode15s and my initial conditions are picked from the random number generator mentioned above.
Walter Roberson
Walter Roberson 2012-5-22
You are setting the seed for the 'state' random number generator, but you are not using that random number generator. 'state' refers to a particular generator algorithm. Setting the internal state for a generator algorithm does not make that generator the active generator.
TUSHAR ANDRIYAS
TUSHAR ANDRIYAS 2012-5-22
Hi Walter,
I am setting the internal state through the rand('state',sum(100*clock)) but the initial conditions are taken from a normally distributed random variable eg x_0 = normrnd(0,.25) and so on.

1 个评论

MATLAB 7.7 (R2008b) and later have multiple simultaneously active random number generators. You can set the internal state for one kind of random number generator using the syntax you use, but that does not activate that particular random number generator as being the one that is used by normrnd(). You have to change the "global" random number stream in order to have an effect on normrnd().
From R2008b until about R2011a or so, the mechanism for doing that was by using RandStream.setGlobalStream, as described in the second link above, http://www.mathworks.com/help/techdoc/math/brufme_.html
Newer versions (R2011b or so onward) added the rng() function to make the interface earlier; using that rng() function is described in the first link I gave above, and some dirty details of converting from older random number generators to use rng() are described in the third link I gave above. These new versions also allow you to use the RandStream class -- rng() does not add new functionality, just a nicer interface to the new functionality added in R2008b.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by