Hi,

1) Given .Random.seed, how can one compute *the* integer 'seed' such

that set.seed(seed) generates .Random.seed?

2) If 1) is not possible, how can one compute *an* integer 'seed' from

a given .Random.seed such that different .Random.seed's are guaranteed

to give different integers 'seed' (or at least with a very high

probability)? In other words, how can one construct an injective

function from .Random.seed objects to an integer?

(In an ideal world, this would work for all kinds of random number generators).

What I found out (... is not very much so far):

./src/main/names.c -> do_setseed() -> RNG.c -> RNG_Init() leads to (at

least for the Mersenne Twister)...

for(j = 0; j < RNG_Table[kind].n_seed; j++) {

seed = (69069 * seed + 1);

RNG_Table[kind].i_seed[j] = seed;

}

FixupSeeds(kind, 1);

... which gives some hope that the first entry in RNG_Table can be

used to access 'seed' (which could be the 3rd value of .Random.seed in

this case, but I'm not sure...).

Background (or 'why on earth would you...'): I have a function myRNG

of the following form (body explains the non-minimal problem):

myRNG <- function(n, method, ...) {

if(method = "A") {

<All random numbers I generate in here respect a global

'set.seed(seed)'

command ('global' in the sense of calling set.seed() before calling 'myRNG').

In particular, different 'seed' arguments of set.seed() correctly

lead to different random numbers.>

} else {

<In here I'm calling a function 'obscure' from another package (which

also generates some random numbers). Unfortunately, 'obscure' does not

respect a global 'set.seed(seed)' (different 'seed' arguments to

set.seed() always lead to the same outputs of 'obscure'). Luckily,

'obscure' accepts an argument 'seed', so one can set a seed inside

'obscure'. However, this argument 'seed' needs to be an integer.

So if 1) or 2) above can be solved, I can use a global set.seed()

and guarantee that different 'seed' arguments to set.seed() lead

to different outputs of 'myRNG' also for this method (!= "A").>

}

}

Thanks & cheers,

Marius

______________________________________________

[hidden email] mailing list -- To UNSUBSCRIBE and more, see

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.