Background. I want to generate random sequences within a for cycle in R v.3.5.0
. To do this I use the code like bellow:
rm(.Random.seed, envir=globalenv())
some_list = list()
for (iter in 1:3) {
set.seed(iter)
some_list[[iter]] = sample(1:10)
}
some_list
This code returns me a list like this:
> some_list
[[1]]
[1] 3 4 5 7 2 8 9 6 10 1
[[2]]
[1] 2 7 5 10 6 8 1 3 4 9
[[3]]
[1] 2 8 4 3 9 6 1 5 10 7
After that I'm rerunning the same script, and expect to have the seed to be reset after running rm(.Random.seed, envir=globalenv())
within session, hence get different result.
But the reality is different - I receive exact the same list even after removal of .Random.seed
from globalenv()
.
Please, see the screen attached with exact sequence of commands:
Sequence of commands
I'm really confused by such behaviour of set.seed.
My question is:
1) Is such behaviour of set.seed normal?
2) How to reset seed if rm(.Random.seed, envir=globalenv())
do not work?
Thanks in advance.
iter
in theset.seed
which is the same. Do you expect ` set.seed(1); sample(1:10)` to show a different value for each run - akrun