操作系统之间产生不同的随机数 [英] Different random number generation between OS

查看:101
本文介绍了操作系统之间产生不同的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都对set.seed根据操作系统(OS)给出不同结果的情况有任何经验.我记得在R上的一个类中遇到过类似的情况,在此之前,有些人使用rmrm生成了不同的随机序列,尽管将起始种子设置为相同的值. 现在,我要自己上一门课程,并且没有遇到与rmrm相同的问题;无论使用什么操作系统,我所有的学生都得到相同的顺序.有趣的是,MASS软件包的mvrnorm函数似乎存在相同的问题.

Does anyone have any experience with situations where set.seed gives different results depending on operating system (OS). I remember coming across a similar situation in a class on R before where some people were generating different random sequences using rnorm despite setting the starting seed to the same value. Now, I'm giving a course myself and have not run into the same issue with rnorm; all my students get the same sequence regardless of OS. Interestingly, the same issue seems to exist with the mvrnorm function of the MASS package.

任何见识将不胜感激-马克

Any insight would be greatly appreciated - Marc

此示例:

require(MASS)
set.seed(123)
a <- rnorm(10, mean=10, sd=3)
b <- rnorm(10, mean=5, sd=2)
df <- data.frame(a,b)
C <- cov(df)
M <- mvrnorm(n=10, c(10,5), C)

df
C
M

在Windows 7 OS 64位版本的R 2.14.1上产生的收益.

Yields on my Windows 7 OS 64-bit version of R 2.14.1.:

> df
           a        b
1   8.318573 7.448164
2   9.309468 5.719628
3  14.676125 5.801543
4  10.211525 5.221365
5  10.387863 3.888318
6  15.145195 8.573826
7  11.382749 5.995701
8   6.204816 1.066766
9   7.939441 6.402712
10  8.663014 4.054417
> C
         a        b
a 8.187336 3.431373
b 3.431373 4.310385
> M
              a        b
 [1,] 13.270535 6.158603
 [2,] 10.375011 5.737871
 [3,] 13.514105 5.476411
 [4,] 12.681956 5.020646
 [5,] 12.352333 4.927746
 [6,] 15.177508 6.810387
 [7,]  8.114377 2.925225
 [8,]  9.529744 4.834451
 [9,] 12.903550 7.232715
[10,]  6.251907 3.481789

了解是否有人没有得到这些结果以及使用了什么操作系统或R版本可能会有所帮助.

It might be helpful to know if anyone is not getting these results and what OS or versions of R were used.

推荐答案

我听说有人在更改RNGKind,有时无法通过加载和运行更改生成器的程序包或进行更改的其他脚本来意识到.如果真是这样,那么同一个种子将导致不同的随机数.重新运行R(无需加载不同的程序包或其他脚本)应从同一种子生成相同的随机数.

I have heard of people changing the RNGKind, sometimes without realizing it by loading and running a package that changed the generator or some other script that made the change. If that was the case then the same seed would lead to different random numbers. A fresh running of R (without loading different packages or other scripts) should generate the same random numbers from the same seed.

这篇关于操作系统之间产生不同的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆