[R] difference between rnorm(1000, 0, 1) and running rnorm(500, 0, 1) twice

Philippe Grosjean phgrosjean at sciviews.org
Wed Feb 8 10:08:18 CET 2006


Romain Francois wrote:
> Le 08.02.2006 04:21, Taka Matzmoto a écrit :
> 
> 
>>Hi R users
>>
>>This looks a simple question
>>
>>Is there any difference between between rnorm(1000,0,1) and running 
>>rnorm(500,0,1) twice in terms of outcome ?
>>
>>TM
>> 
>>
> 
> Not here :
> 
> R> set.seed(1)
> R> x <- rnorm(1000, 0, 1)
> R> set.seed(1)
> R> y <- rnorm(500, 0, 1)
> R> z <- rnorm(500, 0, 1)
> R> all(x == c(y,z))
> [1] TRUE
> 
> Romain

Indeed! The pseudo-random number generator is initialized at the same 
state, and thus, returns the same 1000 pseudo-random numbers in both 
cases. So, no differences.
Best,

Philippe Grosjean




More information about the R-help mailing list