This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran] PATCH -- Fix segfault in RANDOM_SEED.
On Wed, May 26, 2004 at 08:39:51PM +0200, Tobias Schl?ter wrote:
> Steve Kargl wrote:
> >I really don't understand your random_generate() function, so
> >I'm of limited help here. I wrote an equipartition test for
> >PRNG and tested your MT. If I seed the array with
> >
> >seed(1:624) = (/ (i,i=1,624) /) or 10 * (/ (i,i=1,624) /)
> >
> >I have to burn 100000 random number before I start to get
> >"good" random numbers with respect to a chi square test.
> >
>
> I'm wondering if this can't be helped by XOR'ing the seed the users
> passes against some value, so that you still get a deterministic set of
> random numbers without having to throw away the first, even if you
> choose to seed the RNG as simply as Steve tried above. I guess Steve's
> problem is tied to having very few bits set in his seed, this could be
> cured this way.
The two sequences for the seeds produced above have the general
form 0x00ZZ in hex. I think you may be right that XOR'ing with a
constant set of pre-define 624 uniformly distributed numbers may
work. I'll note that the standard is going to complicate this
XOR'ing.
The pseudorandom number generator used by RANDOM_NUMBER maintains a
seed that is updated during the execution of RANDOM_NUMBER and that
may be specified or returned by RANDOM_SEED. Computation of the seed
from the argument PUT is performed in a processor-dependent manner.
The value returned by GET need not be the same as the value specified
by PUT in an immediately preceding reference to RANDOM_SEED. For
example, following execution of the statements
CALL RANDOM_SEED (PUT=SEED1)
CALL RANDOM_SEED (GET=SEED2)
SEED2 need not equal SEED1.
So far so go. XOR'ing will statisfy the above requirement. However,
this is where the fun begins.
When the values differ, the use of either value as the PUT
argument in a subsequent call to RANDOM SEED shall result in the
same sequence of pseudo-random numbers being generated. For example,
after execution of the statements
CALL RANDOM_SEED (PUT=SEED1)
CALL RANDOM_SEED (GET=SEED2)
CALL RANDOM_NUMBER (X1)
CALL RANDOM_SEED (PUT=SEED2)
CALL RANDOM_NUMBER (X2)
X2 equals X1.
We now need a flag to note that seeds were set by the user and
we will need to save internal copies of SEED1 and SEED2 to
check a subsequent call to RANDOM_SEED(PUT=) against SEED1
and SEED2. So we now, have 624 values for XORing and another
1248 values of user defined seeds.
>
> Seems like an easier fix than writing a whole new RNG.
>
It took 30 to 60 minutes to modify Marsgalia's KISS PRNG
to replace the MT and AFAICT it meets the requirements of
the standard. I sent Marsaglia email to check if he had
any objections to using KISS in gfortran, but he hasn't
responded, yet. I'll also note that I had Lars' implementation
to help reduce the time.
--
Steve