About normal random number generator
Show older comments
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
Answers (3)
TUSHAR ANDRIYAS
on 22 May 2012
0 votes
Walter Roberson
on 22 May 2012
0 votes
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
on 22 May 2012
0 votes
1 Comment
Walter Roberson
on 22 May 2012
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.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!