Find the seed from set.seed() associated with a fixed random simulation in R

时间:2015-12-14 18:00:06

标签: random simulation random-seed

My problem is :

I've already saved a workspace with a fixed simulation that I called X1 from :

alpha=c(0,0.05,0.25,0.5,0.75,0.95,1)
w1=alpha
w2=1-alpha
n=100
m1=2
m2=6
X=matrix (nrow=n,ncol=length(w1))   # on l'appelle X ici mais cela est également notre X1 dans le rapport. 
for (i in 1:length(w1))
   { 
w=sample(c(1,2), size = n, replace = TRUE, prob = c(w1[i],w2[i]))
X[,i]=(w==1)*rnorm(n,m1,1)+(w==2)*rnorm(n,m2,1)         
}    

My problem is that I want to get the seed associated to this particular simulation of X(nrow=100,ncol=7) so that I could re-use it more easily.

I don't know if this could be implemented numerically in R ? And in general ?

1 个答案:

答案 0 :(得分:0)

您可以在set.seed循环之前使用for函数。这样可以确保samplernorm生成相同的结果。

有关详情,请查看?set.seed

使用示例set.seed(123)

要查看实际使用的种子,请尝试.Random.seed