[Rd] user supplied random number generators

Petr Savicky savicky at cs.cas.cz
Tue Aug 18 08:39:42 CEST 2009


On Mon, Aug 17, 2009 at 12:25:57PM -0700, Ross Boylan wrote:
> > Seeding by a vector is also available in the initialization of Mersenne Twister
> > from 2002. See mt19937ar.c (ar for array) at
> >   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
> > Unfortunately, seeding by a vector is not available in R base. R uses
> > Mersenne Twister, but with an initialization by a single number.
> I think that one could write to .Random.seed directly to set a vector
> for many of the generators.  ?.Random.seed does not recommend this and
> notes various limits and hazards of this strategy.

Initialization of a generator by writing the initial state into .Random.seed
is possible, but requires to know the exact form of the admissible states
of the generator. An error leads to a corrupted sequence. So, this is indeed
not suggested.

By seeding by a vector, i mean something different. The user provides
a vector of arbitrary length and this vector is used as an input to 
a hash function, which produces a correct initial state. The advantage
over seeding by a single number is that the set of possible initial states
is much larger already if we use a seed of length 2 or 3.

Seeding by a vector is available, for example, in Mersenne Twister from 2002
using the C function init_by_array() in mt19937ar.c.

In the package rngwell19937, the R function set.vector.seed() may be used
for the same purpose.

I will reply to the rest of your message in a private email (as was also
the email you were replying to).

Petr Savicky.



More information about the R-devel mailing list