This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran] PATCH -- Fix for PR 15619
- From: Paul Brook <paul at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>,gcc-patches at gcc dot gnu dot org
- Date: Thu, 27 May 2004 00:12:59 +0100
- Subject: Re: [gfortran] PATCH -- Fix for PR 15619
- Organization: CodeSourcery
- References: <20040526221214.GA79363@troutmask.apl.washington.edu>
On Wednesday 26 May 2004 23:12, Steve Kargl wrote:
> There were 2 problems that led to PR 15619. First, a global
> index was used where a local index should have been used.
> This caused the global index to either retain a wrong value
> or reset to new value when RANDOM_SEED(GET=) was called.
> The second problem was the global index needs to be reset
> to N on each call to RANDOM_SEED(PUT=). This then causes
> the sequence to be regenerated.
>
> 2004-05-26 Steven G. Kargl <kargls@comcast.net>
>
> * random.c (random_seed): Use local index. Reset global index.
No, still wrong. Fails the test appended to this mail.
Possible solution: add an extra word to the seed which contains the current
position. Obviously you'll need to cope with arbitary values when the user
specifies PUT=, but curent_index=abs(current_index) % N should do the trick.
Oh, and while you're at it, please rename the global variable "i" to something
more sane ;)
Paul
program prog
integer, allocatable :: a(:)
integer n
real w, x, y, z
call random_seed(size=n)
allocate(a(n))
call random_number (x)
call random_seed(get=a)
call random_number(x)
call random_seed(put=a)
call random_number(y)
if (x .ne. y) call abort ()
end program