[R] set.seed

ronggui ronggui.huang at gmail.com
Wed Jun 14 11:38:02 CEST 2006


set.seed is used to set the random number seed.
When we use functions ,say runif, to generate random number ,we almost
get different set of random number.
> runif(5)
[1] 0.2096388 0.3427873 0.5455948 0.7694844 0.4287647
> runif(5)
[1] 0.6864617 0.5218690 0.7965364 0.9030520 0.4324572

But in some cases,we want the results reproducible.so we use set.seed
before generate the number.
>set.seed(100)
> runif(5)
[1] 0.30776611 0.25767250 0.55232243 0.05638315 0.46854928
> set.seed(100)
> runif(5)
[1] 0.30776611 0.25767250 0.55232243 0.05638315 0.46854928

So if you set the same random number seed before you generate the
number,you get the same result.(That's why we call it pesudo-random
number.)

As for what the i in set.seed(i) should be,I don't think it is a serious matter.



2006/6/14, Xiaohua Dai <ecoinformatics at gmail.com>:
> Hi R users,
>
> Sorry for a simple question:
> I found different people use different i in set.seed(i), are there any
> rules to choose an i or one can choose as he likes?
>
> Thanks
> Xiaohua
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>


-- 
»ÆÈÙ¹ó
Deparment of Sociology
Fudan University



More information about the R-help mailing list