If I am using
Threads.@threads to run my Monte Carlo simulation in paralell, how do I set up Mersenne Twister RNGs for each thread so that I am both able to set a seed, in order to be able to reproduce the results, but also set a random seed when not wanting reproducability?
Now I am using a “home cooked” skip-ahead solution (which I am not even sure is correct/at least not robust) .
function set_rngs(num_draws_per_path,num_paths) seed_1 = 1234; seed_2 = seed1+num_draws_per_path*num_paths/4; seed_3 = seed2+num_draws_per_path*num_paths/4; seed_4 = seed3+num_draws_per_path*num_paths/4; return [MersenneTwister(seed_1),MersenneTwister(seed_2),MersenneTwister(seed_3),MersenneTwister(seed_4)]; end
rngs = set_rngs(s,num_paths) and
Threads.@threads for p=1:num_paths rand_nums = randn(rngs[Threads.threadid()],num_draws_per_path); do stuff..... end ``