Is it possible to use the set.seed()
in a local environment not affecting the following random number generation? It is common use to set the seed in some functions to get reproducible results but I think this is unfortunate as it affects the following generations of random numbers even outside the environment.
Is there any possibility to avoid this behaviour?
set.seed(123)
runif(1) #[1] 0.2875775
runif(1) #[1] 0.7883051
local({
set.seed(123)
print(runif(1))
})
#[1] 0.2875775
runif(1) #[1] 0.7883051 (This should not be the second number again)