This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
"Mersenne Twister with improved initialization" (2002): default seed varies in different implementations
- From: "Paul C. Leopardi" <leopardi at physics dot usyd dot edu dot au>
- To: m-mat at math dot sci dot hiroshima-u dot ac dot jp, jrfsousa at esoterica dot pt, gsl-discuss at sourceware dot org
- Date: Wed, 29 Nov 2006 13:31:44 +1100
- Subject: "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations
- Reply-to: paul dot leopardi at usyd dot edu dot au
To Makoto Matsumoto, Josi Rui Faustino de Sousa, gsl-discuss mailing list.
Hi all,
The purpose of this email message is to document the different default seeds
used by some of the different implementations of "Mersenne Twister with
improved initialization" (2002).
In summary, the value used by the original authors is 5489UL. GSL 1.8 uses the
obsolete value 4357. Josi Rui Faustino de Sousa's mt19937ar.f90 uses the
incorrect value 21641. This is fixed in mt95.f90. See details below.
Some suggestions for various authors:
1. Document the reason for changing the default seed of mt19937ar.c from 4357
to 5489UL.
2. Update mt.c GSL to use the value 5489UL rather than 4357.
3. Document the default seed bug in mt19937ar.f90 (2002).
4. Update the web page "Mersenne Twister in FORTRAN"
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/FORTRAN/fortran.html
to note the bug in mt19937ar.f90 (2002) and to list mt95.f90 (2003).
Best regards, Paul
Details:
GSL 1.8:
Function mt_set in gsl-1.8/rng/mt.c contains the code:
if (s == 0)
s = 4357; /* the default seed is 4357 */
The value 4357 is the default seed used in the 1998 version
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/980409/mt19937int.c
and the 1999 version
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/991029/mt19937int.c
but not in mt19937ar.c (2002).
mt19937ar (2002):
Function genrand_int32 in
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
contains the code:
if (mti == N+1) /* if init_genrand() has not been called, */
init_genrand(5489UL); /* a default initial seed is used */
Also, calling function init_genrand(s) with s == 0UL will use an initial seed
value of 0 rather than 5489UL or 4357.
mt19937ar.f90 (2002):
Function genrand_int32 in
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/FORTRAN/mt19937ar.f90
contains the code:
data seed_d /z'5489'/
! ...
if ( mti > n ) then ! generate N words at one time
if ( .not. mtinit ) call init_genrand( seed_d )
! if init_genrand() has not been called, a default initial seed is used
Here Josi Rui Faustino de Sousa has apparently made an error by using hex
instead of decimal, resulting in the default seed being 0x5489 == 21641
rather than 5489UL as used in mt19937ar.c (2002).
Also, calling subroutine init_genrand(s) with s == 0UL will use an initial
seed value of 0 rather than 0x5489 or 5489UL or 4357.
mt95.f90 (2003):
The web page "Mersenne Twister in FORTRAN"
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/FORTRAN/fortran.html
lists mt19937ar.f90 (2002) but does not list mt95.f90 (2003) which can be
found at http://homepage.esoterica.pt/~jrfsousa/files/mt95.htm
and http://homepage.esoterica.pt/~jrfsousa/files/mt95.zip
Module mt95 in mt95.f90 (2003) contains the code
integer(kind=wi), private, parameter :: default_seed = 5489_wi
so the default seed used in mt95.f90 (2003) matches the one used in
mt19937ar.c (2002). In other words, mt95.f90 (2003) fixes the default seed
bug in mt19937ar.f90 (2002).
--
Paul Leopardi, School of Physics, University of Sydney