[R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

Marius Hofert marius.hofert at math.ethz.ch
Thu Jan 24 18:33:26 CET 2013

Thanks a lot, Duncan, that solved it!



Duncan Murdoch writes:

> On 13-01-24 2:09 AM, Marius Hofert wrote:
>> Dear Daniel,
>> That's exactly what I also suspected (last post). The question now seems how to
>> correctly convert .Random.seed from signed to unsigned so that it is accepted by
>> the rlecuyer package.
> The rlecuyer package assumes that seed values are positive internally, because
> it does this conversion in the C code:
> seed[i]= (unsigned long) REAL(sexp_seed)[i]
> If you send it negative values, the result of this is undefined.
> I'd suggest that the .lec.CheckSeed function should check for this and quit if
> it's not true.
> When you tried to convert everything to be positive, you used
> seed <- .Random.seed[-1] + 2^32
> This will put negative values into the right range, but positive values will end
> up too big, and again the results in the C code will overflow.
> You should be able to get proper behaviour this way:
> seed <- .Random.seed[-1]
> seed <- ifelse(seed < 0, seed + 2^32, seed)
> which puts values into the legal range for an unsigned int.  When I do this, I
> don't get an error running
> .lec.SetPackageSeed(seed)
> You got an error Seed[1] >= 14, which comes from an error in the rlecuyer
> package formatting of the error message.  It is printing a floating point value
> using a %d format, instead of %f.
> Duncan Murdoch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130124/752b6714/attachment.bin>

More information about the R-help mailing list