[R] Random Sample

Giovanni Petris gpetris at uark.edu
Mon Nov 8 23:46:01 CET 2010


Here is an example of what I think the original poster wanted to
achieve.

> rnorm(10)
 [1] -1.2165869 -0.4698460 -0.4209811 -1.4856052  0.3765774 -1.3822470
 [7]  0.2818458  0.5500957 -1.1474455 -1.2221257
> x <- .Random.seed
> runif(10)
 [1] 0.5610780 0.5911841 0.5868183 0.3833801 0.7397059 0.4973270 0.6544219
 [8] 0.1257485 0.2756357 0.5672207
> .Random.seed <- x
> runif(10)
 [1] 0.5610780 0.5911841 0.5868183 0.3833801 0.7397059 0.4973270 0.6544219
 [8] 0.1257485 0.2756357 0.5672207
 
Best,
Giovanni Petris

On Mon, 2010-11-08 at 16:05 -0500, Jorge Ivan Velez wrote:
> Hi Xiaoxi,
> 
> Take a look at the following:
> 
> > set.seed(123)
> > rnorm(10)
>  [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
>  [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
> > rnorm(10)
>  [1]  1.2240818  0.3598138  0.4007715  0.1106827 -0.5558411  1.7869131
>  0.4978505
>  [8] -1.9666172  0.7013559 -0.4727914
> > set.seed(123)
> > rnorm(10)
>  [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
>  [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
> 
> and check ?set.seed().
> 
> HTH,
> Jorge
> 
> 
> On Mon, Nov 8, 2010 at 3:57 PM, Xiaoxi Gao <> wrote:
> 
> >
> > Hello R users,
> > Here is my question about generating random sample. How to set the random
> > seed to recreate the same random numbers?  For example, 10 random numbers is
> > generated from N(0,1), then "runif(10)" is used.What if I want to get the
> > same 10 random numbers when I run runif(10) again? Is it possible?I think
> > .Random.seed should be used here.
> > Thanks.
> > Xiaoxi
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 

Giovanni Petris  <GPetris at uark.edu>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/



More information about the R-help mailing list