[Bug fortran/98253] Conflicting random_seed/random_init results

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Dec 12 18:20:44 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98253

--- Comment #3 from kargl at gcc dot gnu.org ---
Third thought.  Here are the programs you meant to write (without error
checking such as how_to_use_random_init must be run before
how_to_seed_with_random_seed_like_random_init).

program how_to_use_random_init

   implicit none

   integer fd, i, n
   integer, allocatable :: seeds(:)
   real r

   call random_init(repeatable=.true., image_distinct=.true.)

   call random_seed(size=n)
   allocate(seeds(n))
   call random_seed(get=seeds)
   open(newunit=fd,file='seed.cache',access='stream',status='replace')
   write(fd) seeds
   close(fd)

   do i=1,5
     call random_number(r)
     print *,r 
   end do

end program how_to_use_random_init

program how_to_seed_with_random_seed_like_random_init

   implicit none

   integer fd, i, n
   integer, allocatable :: seeds(:)
   real r

   call random_seed(size=n)
   allocate(seeds(n))
   open(newunit=fd,file='seed.cache',access='stream',status='old')
   read(fd) seeds
   close(fd)

   call random_seed(put=seeds)
   do i=1,5
      call random_number(r)
      print *,r 
   end do

end program how_to_seed_with_random_seed_like_random_init


More information about the Gcc-bugs mailing list