尽管 set.seed - 我得到的结果与 R 中的其他人不同
Despite set.seed - I get different results than others in R
做的时候
set.seed(123)
smaple(1:100,3)
在 R 中,我得到 29 79 41
,这不是其他人得到的。
为什么是这样?我该如何更改它?
当输入 sessionInfo()
时,我得到一行
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
这可能是个问题吗?
我们可以更改 RNGkind
中的默认值
-R 4.1.0
中的默认设置 - MacOS(可能因 R 版本而异 - 见下文)
RNGkind()
#[1] "Mersenne-Twister" "Inversion" "Rejection"
-测试
set.seed(123)
sample(1:100, 3)
#[1] 31 79 51
-更改 RNGkind
中的值以匹配 OP 的
RNGkind(kind = "Mersenne-Twister",
normal.kind = "Inversion",
sample.kind = "Rounding")
-再次测试
set.seed(123)
sample(1:100, 3)
[1] 29 79 41
根据?RNGkind
sample.kind can be "Rounding" or "Rejection", or partial matches to these. The former was the default in versions prior to 3.6.0: it made sample noticeably non-uniform on large populations, and should only be used for reproduction of old results. See PR#17494 for a discussion.
做的时候
set.seed(123)
smaple(1:100,3)
在 R 中,我得到 29 79 41
,这不是其他人得到的。
为什么是这样?我该如何更改它?
当输入 sessionInfo()
时,我得到一行
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
这可能是个问题吗?
我们可以更改 RNGkind
-R 4.1.0
中的默认设置 - MacOS(可能因 R 版本而异 - 见下文)
RNGkind()
#[1] "Mersenne-Twister" "Inversion" "Rejection"
-测试
set.seed(123)
sample(1:100, 3)
#[1] 31 79 51
-更改 RNGkind
中的值以匹配 OP 的
RNGkind(kind = "Mersenne-Twister",
normal.kind = "Inversion",
sample.kind = "Rounding")
-再次测试
set.seed(123)
sample(1:100, 3)
[1] 29 79 41
根据?RNGkind
sample.kind can be "Rounding" or "Rejection", or partial matches to these. The former was the default in versions prior to 3.6.0: it made sample noticeably non-uniform on large populations, and should only be used for reproduction of old results. See PR#17494 for a discussion.