I would like to produce a reproducible random number sequence with parfor. I do not want to create a new random stream for each worker, but supply the workers with distinct and deterministic segments of a global random stream. I tried using instructions on this page (<http://www.mathworks.com/help/stats/reproducibility-in-parallel-statistical-computations.html)>, but it did not work for me.
if true s = RandStream('mlfg6331_64'); options = statset('UseParallel',true,'Streams',s,'UseSubstreams',true); agent = zeros(3,2); parfor ind = 1:indn agent(ind,:) = [randi(10), randi(10)]; end agentend
I can use the following code to achieve my goal, but that is not efficient, and I fear creating correlations between the parfor index and random numbers generated.
if true agent = zeros(3,2); parfor ind = 1:indn rng(ind); agent(ind,:) = [randi(10), randi(10)]; end agentend
Best Answer