mardi 10 avril 2018

Pseudo-random sequence interfered by another pseudo-random generator

I have noticed that if one uses another pseudo-random number generator when generating a pseudo-random sequence, the seed sequence is interfered. My question is if there is anything to do about it? Can you somehow ensure original seed sequence is continued? Let me show an example;

A simple for-loop which prints a pseudo-random number drawn from the normal distribution:

set.seed(145)
for (i in 1:10){
print(rnorm(1,0,1))
}

Which gives the following output:

[1] 0.6869129
[1] 1.066363
[1] 0.5367006
[1] 1.906029
[1] 1.06316
[1] 1.370344
[1] 0.5277918
[1] 0.4030967
[1] 1.167752
[1] 0.7926794

Next, we introduce a pseudo-random draw from the uniform distribution if the iterator is equal to five.

set.seed(145)
for (i in 1:10){
  print(rnorm(1,0,1))
  if (i == 5){
    print(runif(1,0,1))
  }
}

Which gives the following output (in the following output, the star marks the pseudo-random draw from the uniform distribution):

[1] 0.6869129
[1] 1.066363
[1] 0.5367006
[1] 1.906029
[1] 1.06316
*[1] 0.9147102
[1] -1.508828
[1] -0.03101992 
[1] -1.091504
[1] 0.2442405
[1] -0.6103299

What I try to seek an answer on, is whether or not it is possible to continue the original seed sequence introduced by set.seed(145), and thereby get the following output:

[1] 0.6869129
[1] 1.066363
[1] 0.5367006
[1] 1.906029
[1] 1.06316
*[1] 0.9147102
[1] 1.370344
[1] 0.5277918
[1] 0.4030967
[1] 1.167752
[1] 0.7926794

Every input is highly appreciated, especially some references to literature on this specific issue.




Aucun commentaire:

Enregistrer un commentaire