* "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations
@ 2006-11-29 2:32 Paul C. Leopardi
2006-11-29 22:51 ` Brian Gough
2006-12-01 4:11 ` "Mersenne Twister with improved initialization" (2002): another bug in mt19937ar.f90 Paul C. Leopardi
0 siblings, 2 replies; 3+ messages in thread
From: Paul C. Leopardi @ 2006-11-29 2:32 UTC (permalink / raw)
To: m-mat, jrfsousa, gsl-discuss
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations
2006-11-29 2:32 "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations Paul C. Leopardi
@ 2006-11-29 22:51 ` Brian Gough
2006-12-01 4:11 ` "Mersenne Twister with improved initialization" (2002): another bug in mt19937ar.f90 Paul C. Leopardi
1 sibling, 0 replies; 3+ messages in thread
From: Brian Gough @ 2006-11-29 22:51 UTC (permalink / raw)
To: paul.leopardi; +Cc: gsl-discuss
Paul C. Leopardi wrote:
> 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)....
Hello,
Thanks for the information, I'll make a note to update that for the next
release.
--
best regards,
Brian Gough
(GSL Maintainer)
Network Theory Ltd,
Publishing the GSL Manual - http://www.network-theory.co.uk/gsl/manual/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: "Mersenne Twister with improved initialization" (2002): another bug in mt19937ar.f90
2006-11-29 2:32 "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations Paul C. Leopardi
2006-11-29 22:51 ` Brian Gough
@ 2006-12-01 4:11 ` Paul C. Leopardi
1 sibling, 0 replies; 3+ messages in thread
From: Paul C. Leopardi @ 2006-12-01 4:11 UTC (permalink / raw)
To: m-mat, jrfsousa, gsl-discuss
To Makoto Matsumoto, Josi Rui Faustino de Sousa, gsl-discuss mailing list.
Hi all,
Further to my recent message, I have discovered another bug in mt19937ar.f90
(2002).
In mt19937ar.f90 (2002), in subroutine init_genrand, the value of mti should
be reinitialized to n + 1_wi, but this is not done. The fix is to add the
line
mti = n + 1_wi
immdiately before
end subroutine init_genrand.
The other implementations, mt19937ar.c (2002), GSL 1.8 and mt95.f90 (2003) do
not have the bug seen here in mt19937ar.f90 (2002).
In mt19937ar.c (2002), in function init_genrand, mti is set to N when the for
loop completes.
In GSL 1.8, in function mt_set of in mt.c, the statement
state->mti = i;
correctly reinitializes state->mti.
In mt95.f90 (2003), in subroutine init_by_scalar, the statement
state%cnt = n + 1_wi
correctly reinitializes state%cnt.
Best, Paul
On Wednesday 29 November 2006 13:31, Paul C. Leopardi wrote:
> 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).
...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-12-01 4:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-29 2:32 "Mersenne Twister with improved initialization" (2002): default seed varies in different implementations Paul C. Leopardi
2006-11-29 22:51 ` Brian Gough
2006-12-01 4:11 ` "Mersenne Twister with improved initialization" (2002): another bug in mt19937ar.f90 Paul C. Leopardi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).