How to set seed for random simulations with foreach and doMC packages?
I need to do some simulations and for debugging purposes I want to use set.seed to get the same result. Here is the example of what I am trying to do: library(foreach) library(doMC) registerDoMC(2) set.seed(123) a <- foreach(i=1:2,.combine=cbind) %dopar% {rnorm(5)} set.seed(123) b <- foreach(i=1:2,.combine=cbind) %dopar% {rnorm(5)} Objects a and b should be identical, i.e. sum(abs(a-b)) should be zero, but this is not the case. I am doing something wrong, or have I stumbled on to some feature? I am able to reproduce this on two different systems with R 2.13 and R 2.14 My default answer used to