[R] How to construct a valid seed for l'Ecuyer's method withgiven .Random.seed?
Daniel Nordlund
djnordlund at frontier.com
Thu Jan 24 00:49:24 CET 2013
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Marius Hofert
> Sent: Wednesday, January 23, 2013 2:24 PM
> To: Hana Sevcikova
> Cc: R-help
> Subject: Re: [R] How to construct a valid seed for l'Ecuyer's method
> withgiven .Random.seed?
>
> Dear Hana,
>
> Thanks for helping.
>
> I am still wondering, why m1 (which should be 2^32-209 [see line 34 in
> ./src/RngStream.c]) is -767742437 in my case and why the minimal example
> you
> gave was working for you but isn't for me.
>
> Apart from that, ?.Random.seed -> "L'Ecuyer-CMRG" says:
>
> ,----
> | The 6 elements of the seed are internally regarded as 32-bit
> | unsigned integers. Neither the first three nor the last
> | three should be all zero, and they are limited to less than
> | ‘4294967087’ and ‘4294944443’ respectively.
> `----
>
> => .Random.seed provides a *signed* integer. I tried to convert it to an
> unsigned integer:
>
> RNGkind()
> set.seed(1)
> .Random.seed[-1]
> RNGkind("L'Ecuyer-CMRG")
> .Random.seed[-1] # => unsigned
>
> seed <- .Random.seed[-1] + 2^32 # => shifting
> require(rlecuyer)
> .lec.SetPackageSeed(seed)
>
> ... but it fails with
>
> ,----
> | Error in .lec.SetPackageSeed(seed) : Seed[1] >= 14, Seed is not set.
> `----
>
> => so there seem to be the requirement that the second element of the seed
> is <
> 14 (???).
>
> I might have done the conversion to a signed integer incorrectly, though.
>
> It would be great if the seed was checked *precisely* (not just basic
> length
> checks) in R, maybe in .lec.CheckSeed(). That would rule out further
> problems
> and strange error messages from C, which are harder to debug.
>
> What are the precise conditions for the seed in 'rlecuyer'? Judging from
> the
> above error, the second element must be < 14. But, additionally,... ?
>
> I hope there is a solution to the problem of "how to convert .Random.seed
> to get
> a valid seed for 'rlecuyer'"... we need that in a package.
>
> Cheers,
>
> Marius
>
>
>
>
> Hana Sevcikova <hanas at uw.edu> writes:
>
> > Marius,
> >
> > I looked it up in the original L'Ecuyer's paper: The seed must be larger
> than
> > 0. Thus, the function defines the seed variable as unsigned long
> integer. You're
> > passing a negative number, so I think there is some overflow going on.
> >
> > The internal L'Ecuyer RNG is a modification of the original one (and I'm
> not
> > familiar with it), but they seem to relax that restriction.
> >
> > Hana
I apologize if this message is posted twice. I am having email problems.
I think the confusion about negative numbers is that R represents the seed values as signed integers, but the underlying C code interprets those values as unsigned integers. At least that is how I read the documentation on .Random.seed
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list