# [R] random seed puzzle

Bickel, David DAVID.BICKEL at PIONEER.COM
Tue Aug 3 00:50:44 CEST 2004

```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)}

To make the randomness requirement more precise:
f.list <- lapply(1:1000, f)
vec1 <- sapply(f.list, function(x){x[1]})
vec2 <- sapply(f.list, function(x){x[2]})
The values of vec1 should be as iid as possible and the values of vec2 should be as iid as possible.

Any help with what I need to add to f would be greatly appreciated.

David
_____________________________
David Bickel  http://davidbickel.com
Research Scientist
Pioneer Hi-Bred International
Bioinformatics & Exploratory Research
7250 NW 62nd Ave., PO Box 552
Johnston, Iowa 50131-0552
515-334-4739 Tel
515-334-6634 Fax
david.bickel at pioneer.com, bickel at prueba.info

This communication is for use by the intended recipient and ...{{dropped}}

```