[R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?
murdoch.duncan at gmail.com
Thu Jan 24 13:09:16 CET 2013
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
You got an error Seed >= 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.
More information about the R-help