Mersenne Twister in FORTRAN
Return to Versions of MT
Hiroshi Takano at Department of Physics at
Keio Univ. kindly wrote Fortran versions:
mt19937.f for real
mt19937int.f for integer.
These codes yielded the same output as C-code in
f77 and f90 on HP-UX 10.20,
g77 on SunOS 4.1.4, and
f77 on NEWS-OS 4.2.1R, but yet to be tested. (1999)
Some reported that this does not work for IBM AIX nor CRAY T3E.
- A restorable
MT19937 code in fortran 90
"I have rewritten the fortran version of MT19937 as a module in Fortran 90.
The code, attached below, should give the same 1000 numbers as the original
For some applications it is useful to be able to save the state of the
random number generator and to restart it at that point in a subsequent
run. Therefore I have added subroutines which allow the user to save and
restore the values of variables mti and mt."
Alan Miller wrote a
Fortran version of MT random number
generator with non-uniform distributions, see
his web site.
A fortran code with revrand()
: it generates prn in reverse order, coded by
at Physics department, University of Oldenburg
gave a fortran code
available for IBM AIX and CRAY T3E:
"I had a little problem compiling mt19937.f for AIX, and some
bigger problems to compile mt19937.f on a CRAY T3E.
The comments on top of the attached file show the changes.
The changes for the T3E are ugly, but it seems to me
the only way to compile the function.
(the compiler issues an error saying that the parameter is
out of range if you use -MAX_INT - 1, it only accepts -MAX_INT.)"
A Fortran-95 code by
Josi Rui Faustino de Sousa
mt19937ar (new initialization 2002/Jan).
(a bug was found in this version.)
See enhanced and bug fixed version:
A Fortran77 code (mt19937ar.f) by Tsuyoshi Tada.
His code is fortran77 version of mt19937ar.c.
In addition to (common) 4-byte INTEGER machines/compilers,
his code works correctly also for machines/compilers whose default
integer-type is 8-byte INTEGER.
He also wrote the fortran test program (mtTest.f)
whose output is completely same as mtTest.c.
(Files mt19937ar.f and mtTest.f were broken. They have been repaired now.
Kenichi Ishikawa kindly wrote A Fortran90 code of MULTIPLE STREAM
His code generates multiple sub streams of Mersenne Twister.
Detailed description is in
his web page (Here is
Japanese page). His FORTRAN code does not contain Japanese.
Rémi Piatek kindly wrote A Fortran95 code of