3

Really curious about this because previously when I ran a long chunk of codes involving 1000 simulations for a particular seed, second run gave different results. I was not sure where did the seed started to lose its effect and had to set seed again every time there is random number generation.

So how does R know when to use the seed I gave it and when to use a random seed again?

shavendy
  • 173
  • 1
  • 1
  • 10
  • 1
    It's valid for a session. That doesn't mean a second run generates the same numbers as the first. See the second answer to this question: https://stackoverflow.com/questions/20624698/fixing-set-seed-for-an-entire-session – neilfws Oct 03 '17 at 05:44

1 Answers1

3

The seed defines the state of the random number generator for all times (in this session). The only thing that can happen is that someone resets it with set.seed(NULL) in which case the current time is used as the new seed. Unfortuantely that can also happen in some package you do not have control about.

Addition: It can also happen that the package changes the kind of RNG used, in which case the seed will also no longer have effect.

AEF
  • 5,408
  • 1
  • 16
  • 30