This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran] PATCH -- Fix segfault in RANDOM_SEED.


On Wed, May 26, 2004 at 09:39:24PM +0200, Tobias Schl?ter wrote:
> Steve Kargl wrote:
> >
> >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.
> >
> Just XOR the seed before filling in seed2 (in RANDOM_SEED) should do the 
> trick, I believe.
> 

CALL  RANDOM_SEED (PUT=SEED1)

  We get SEED2 = SEED1^MASK

CALL  RANDOM_SEED (GET=SEED2)

  SEED1 != SEED2 because of ^ MASK.

CALL  RANDOM_NUMBER (X1) 

CALL  RANDOM_SEED (PUT=SEED3)

  Now what?

  case 1:  If (SEED3 == SEED1) then set SEED3^MASK to get us back to SEED2.
           Since saved a copy of SEED2 for the comparison in case 2, we can
           simply set the current seeds to SEED2.
  case 2:  If (SEED3 == SEED2) then set the current seeds to SEED2 or set
           the current seeds to SEED1^MASK to get us back to SEED2.  Note
           "CALL RANDOM_NUMBER(X1)" above may have changed the current
           values of seeds to something not equal SEED2.  Also, note
           SEED1 = SEED3^MASK, which is not what we want.
  case 3:  If (SEED3 != SEED1 and SEED3 !=  SEED2) then set SEED3^MASK
           to get new seeds.

CALL  RANDOM_NUMBER (X2)

   case 1:  X1 == X2
   case 2:  X1 == X2
   case 3:  Mostly like X1 !=  X2

Of course, I could be missing something.  Saving MASK, SEED1, and SEED2
is 7488 bytes.

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]