RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984));
sets the randsom stream to a particular state. (1984 because this is the most True state). Make sure you run this before every invocation of rand
:
>> RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984));
>> rand(3)
ans =
0.1849 0.2629 0.3404
0.1283 0.6475 0.3051
0.7410 0.3623 0.0791
and running it again gives:
>> RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984));
>> rand(3)
ans =
0.1849 0.2629 0.3404
0.1283 0.6475 0.3051
0.7410 0.3623 0.0791