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
This example:
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
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
Edit: It might be helpful to know if anyone is not getting these results and what OS or versions of R were used.
Random number generators can also be built from "random" macroscopic processes, using devices such as coin flipping, dice, roulette wheels and lottery machines. The presence of unpredictability in these phenomena is supported by the theory of unstable dynamical systems and chaos theory.
There are generally two kinds of random number generators: non-deterministic random number generators, sometimes called "true random number generators" (TRNG), and deterministic random number generators, also called pseudorandom number generators (PRNG).
In this program we call the srand () function with the system clock, to initiate the process of generating random numbers. And the rand () function is called with module 10 operator to generate the random numbers between 1 to 10. srand(time(0)); // Initialize random number generator.
Computers are often required to produce random numbers as they're useful for a host of tasks, from taking random samples of data to simulating the formation of galaxies. But computers produce these numbers using mathematical formulas, which means they aren't truly random.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With