How do I reproduce the same set of unique random numbers within PARFOR in Parallel Computing Toolbox 5.0 (R2010b) ?

조회 수: 1 (최근 30일)
I would like to generate the same set of unique random numbers within PARFOR in order to reproduce my simulation.

답변 (1개)

Sanchali Purandare
Sanchali Purandare 2011년 1월 16일
This could be done in the following manner:
seeds = randi(2^31-1,1,10, 'int32')
parfor ii=1:10
rdstm = RandStream.create('mrg32k3a');
reset(rdstm, seeds(ii));
x(ii,:) = rdstm.randn(1,1);
end
In the code above, each loop iteration will create a new random stream and will initialize it to some random seed that comes from the outside. So this way as long as you start from the same set of seeds, you can reproduce the simulation. Also,each loop iteration will create its own random number independent of each other loop iteration.

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by