Hi, I have a lengthy Matlab script for a stochastic simulation model. Every time I run a simulation, I initialize the random number generator at the top of the code by using
s = RandStream('mt19937ar','Seed',seedi);
I expect that I should get the same results as long as the value of seedi is the same, but it is not. I set the number of CPUs to 1
LASTN = maxNumCompThreads(1)
to avoid possible complications due to using multiple CPUs. But this did not solve the problem. Why is this happening? I also tried rng(seedi, 'twister') but it did not solve the problem, either. The script uses many matlab functions that use random numbers (randsample, gamrnd, poisoned, etc) for very numerous times. Is there any possibility that these functions might be resetting the seed somehow in the background? If so, how can I stop it? I need a consistent stream of random numbers for debugging.