how to use the state of random number seed

I am running a matlab script on Matlab 2009a which has a for loop for 100 (say 1-100) iterations. Body of for loop contains some some operations using random numbers. I am setting the random number stream and am saving its state as follows.
strm = RandStream('mt19937ar','Seed',1);
RandStream.setDefaultStream(strm)
for 1:100
.
.
.
end
savedState=strm.State
save xyz.mat
Now I want to run another script for running next 200 iterations (say 101-300) by loading the xyz.mat file. I want to get the same results as I will get by running 1-300 iterations without actually running all 300 iterations again. How should I set my random number seed and state in the new script? Please help.

Answers (1)

dpb
dpb on 27 Jun 2014
Retrieve the savedState structure and begin the script with resetting to that condition. The example of randstream demonstrates precisely that operation.
It could be simpler to simply use the rng simplified interface for a single stream. See the doc for it and the example therein for its usage.

2 Comments

Thanks for the reply. Can you tell me exact usage of randstream in this particular case?
Exactly like the examples...

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Tags

No tags entered yet.

Asked:

on 27 Jun 2014

Commented:

dpb
on 27 Jun 2014

Community Treasure Hunt

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

Start Hunting!