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.


Steve Kargl wrote:
   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.



I don't know what you meant precisely in your e-mail, I'll just walk through my suggestion in a pseudo-debugging manner:


CALL RANDOM_SEED (PUT=SEED1)

-> seed = SEED1 ^ MASK ('seed' denotes the RNG's internal seed)

CALL RANDOM_SEED (GET=SEED2)

-> SEED2 = seed ^ MASK = SEED1 ^ MASK ^ MASK = SEED1 (*)

    CALL  RANDOM_NUMBER (X1)
	
	-> X1 = something

CALL RANDOM_SEED (PUT=SEED2)

-> seed = SEED2 ^ MASK = SEED1 ^ MASK (by (*))

CALL RANDOM_NUMBER (X2)

-> X2 = X1

Which is what we want. The trick is of course that the operation (.)^X^X is the identity operation.

Perhaps I have missed something. As I said, I have other stuff to attend right now, so I can't double-check this. I'm sorry for wasting your time, if I'm wrong.

- Tobi


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