Re: [R] set.seed

From: Barry Rowlingson <B.Rowlingson_at_lancaster.ac.uk>
Date: Wed 14 Jun 2006 - 19:57:20 EST

ronggui wrote:
> 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.

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

The help for set.seed tells you all you need to know. 'i' must be a single value "interpreted as an integer".

  You can give it a decimal number, but it makes it an integer:

 > set.seed(pi)
 > runif(2)
[1] 0.1680415 0.8075164
 > set.seed(3)
 > runif(2)
[1] 0.1680415 0.8075164

  But not too big an 'integer':

  > set.seed(1e100)
  Error in set.seed(1e+100) : supplied seed is not a valid integer   In addition: Warning message:
  NAs introduced by coercion

  because 1e100 isn't represented as an integer internally (in C/Fortran code, its a 'float' or'double precision' type of thing.

  For me it takes signed 32 bit integers, so the limits are +/- 2147483647:

  > set.seed(2147483647)
  > set.seed(-2147483647)
  > set.seed(-2147483648)

  Error in set.seed(-2147483648) : supplied seed is not a valid integer   In addition: Warning message:
  NAs introduced by coercion
  > set.seed(2147483648)
  Error in set.seed(2147483648) : supplied seed is not a valid integer   In addition: Warning message:
  NAs introduced by coercion

A 32 bit integer gives you over 4 billion possible random sequences. Is that enough?

Barry



R-help@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 Received on Wed Jun 14 21:17:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 14 Jun 2006 - 22:12:00 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.