1
$\begingroup$

I'm running a Monte Carlo simulation with 200+ input variables which I'm varying with a zero mean normal distribution via a random number generator. Does it matter if I set the seed once and then perform 1,000 runs, or do I need to reset the seed on the random number generator before each of the 1,000 runs?

As a quick test, I wrote up a test in Matlab to answer this question -- Are 10,000 random numbers pulled from the same seed nearly statistically equivalent to 10,000 random numbers pulled from 10,000 different seeds?

numCases = 10000;
% Same seed
rng(42056)
Xsame = randn(numCases,1);

% Different Seeds
Xdifferent = zeros(numCases,1);
for ii = 1:10000
    rng('shuffle');
    Xdifferent(ii) = randn();
end

This produced means on the same order of magnitude, but I wasn't sure if that was good enough, or if I was missing some understanding of random number generators and Monte Carlo simulations.

$\endgroup$
4
$\begingroup$

For pseudo-random numbers, the seed is not there to "ensure randomness". In fact, it is quite the opposite: the seed is there to ensure reproducibility. You set the seed if you want to be able to run the same pseudo-random Monte Carlo experiments again and get the exact same results. For example if your scripts will be archived with an eventual publication.

It does not make sense to set the seed 10,000 times. You could set it once at the beginning of each of your 1,000 runs, but if they are quick and all run in a single loop, then setting the seed once at the beginning should be fine.

$\endgroup$
  • $\begingroup$ I suppose resetting and recording the seed for each run would enable rerunning specific run cases if desired instead of the full set. Or, to enable a continuation of runs if the full set cannot be run all at once. $\endgroup$ – Patrick Sep 15 '16 at 23:02
  • 1
    $\begingroup$ @Patrick or if the runs are concurrent, as this sort of Monte Carlo is about as embarassingly parallel as it gets! $\endgroup$ – GeoMatt22 Sep 16 '16 at 2:05
  • $\begingroup$ To add a comment on this accurate answer, setting the seed anew for each of 10⁴ simulations will produce a pseudo-random sample only if the renewal mechanism for the seeds produces a sequence of pseudo-independent seeds. The easiest way to achieve this goal is to set the seed once and let the pseudo-random generator proceed through the generation of the 10⁴ values, as the associated seeds are then pseudo-independent. (I use pseudo everywhere to stress everything is deterministic.) $\endgroup$ – Xi'an Sep 16 '16 at 6:42
  • $\begingroup$ @Xi'an good point, thank you for mentioning it explicitly! $\endgroup$ – GeoMatt22 Sep 16 '16 at 23:18
  • $\begingroup$ If you set the MASON agent-based simulatiion framework to run a bunch of simulations in parallel, by default it will generate an initial seed in a usual way (timestamp and other system parameters, I think), and then increment that seed once to produce a new seed for each of the distinct runs. This is probably a reasonable strategy because MASON uses a fairly high-quality PRNG, a Mersenne Twister (and initializes it properly by throwing away the first several hundred numbers after seeding an instance of it, which is appropriate for MT). $\endgroup$ – Mars May 12 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.