[R] random seed puzzle

Duncan Murdoch murdoch at stats.uwo.ca
Tue Aug 3 06:03:00 CEST 2004


On Mon, 2 Aug 2004 17:50:44 -0500, "Bickel, David"
<DAVID.BICKEL at PIONEER.COM> wrote:

>After reading the help page on set.seed, I am unsure about how to solve the following problem. I need to call function f a thousand times. The list of values returned by f, should be as random as possible. f calls g twice:
>	f <- function(){g1 <- g(1); g2 <- g(2); c(g1; g2)}
>The function g in turn calls sample and returns a number, but also depends on its argument, so, starting from the same seed, g(1) returns a different number than g(2). I need each call to g to start with the same random number seed, so that the values returned by f would not be affected by redefining it this way:
>	f <- function(){g2 <- g(2); g1 <- g(1); c(g1; g2)}

This is a problem that's like what people doing simulations on
parallel computers worry about.  You might want to look at the sprng
package.  (I haven't used it, so I'm not sure it does what you need). 

Duncan Murdoch




More information about the R-help mailing list