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: randomizing the seed - unintuitive behaviour


On Sun, Feb 27, 2005 at 01:07:59AM -0500, Kamaraju Kusumanchi wrote:

(snip)
> 
> I agree that this behaviour is standard conforming. But it is counter
> intuitive. I tried intel compiler (ifort 8.1). It does what I want to
> do.

(snip)

> 
> Do the experts consider this as a bug or is it a feature?
> 

You answered your own question!  gfortran's implementation
of random_number and random_seed conform to the standard.
The "experts" (whatever that means) will agree to disagree.

If you want a different sequence with each invocation,
then learn to seed random_number.

      integer nrand, val(8)
      integer, allocatable, dimension(:) :: put
      call date_and_time(values=val)
      call random_seed(size=nrand)
      allocate(put(nrand))
      if (nrand > 8) put = 1
      put = val(1:nrand)
      call random_seed(put=put)

There are better ways to do this.

-- 
Steve


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