Re: [R] Initialising Mersenne-Twister with one integer

From: Gad Abraham <>
Date: Tue 26 Sep 2006 - 23:29:40 GMT

Prof Brian Ripley wrote:
> On Mon, 25 Sep 2006, Gad Abraham wrote:

>> Hi,
>> It seems to me that the Mersenne-Twister PRNG can be initialised using
>> one integer instead of 624 integers, since inside RNG.c code there's a
>> function defined as MT_sgenrand(Int32).
>> How do I actually set this seed within R?

> set.seed(), on the help page for ?.Random.seed.
>> I've tried:
>> > .Random.seed <- c(3, 1)
>> > runif(1)
>> Error in runif(1) : .Random.seed has wrong length

>> From the help page

> '.Random.seed' is an integer vector, containing the random number
> generator (RNG) *state* for random number generation in R. It can
> be saved and restored, but should not be altered by the user.
Ah yes, now I see that .Random.seed is the state, not the actual seed.


>> In addition, is '3' actually the correct rng.kind for the 
>> Mersenne-Twister?
>> I'm using R version 2.2.1, 2005-12-20 on Ubuntu Dapper Linux 686.

> Not current, but I suspect the help page is the same in that version.

Thanks for clarifying that, now I can ask my next question:

I would like to set the same seed in R and in another implementation of the Mersenne-Twister ( by Sean Luke, at, in order to get the same set of random deviates.

In Java:

    MersenneTwister mt = new MersenneTwister(1); // set seed     System.out.println("result = " + mt.nextDouble());     // result is 0.4170220046815992

In R:

    > set.seed(1, kind = "Mersenne-Twister")     > runif(1)
    [1] 0.2655087

Why are the random deviates different?


Gad Abraham
Department of Mathematics and Statistics
University of Melbourne
Parkville 3010, Victoria, Australia

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed Sep 27 09:33:56 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 00:30:07 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.