Bug 98253 - Conflicting random_seed/random_init results

Damian Rouson damian@sourceryinstitute.org
Sat Dec 12 16:27:26 GMT 2020


16.9.155 Case (i) in the Fortran 2018 standard states

  CALL RANDOM_INIT (REPEATABLE=true, IMAGE_DISTINCT=true) is equivalent to
  invoking RANDOM_SEED with a processor-dependent value for PUT that is
  different on every invoking image. In each execution of the program with
  the same execution environment, if the invoking image index value in the
  initial team is the same, the value for PUT shall be the same.

but the two programs below give different results.

% cat random_init.f90
  implicit none
  integer i
  real r
  call random_init(repeatable=.true., image_distinct=.true.)
  do i=1,5
    call random_number(r)
    print *,r
  end do
end

% cat random_seed.f90
  implicit none
  integer i, n
  real r
  call random_seed(size=n)
  call random_seed(put=[(i,i=1,n)])
  do i=1,5
    call random_number(r)
    print *,r
  end do
end

% /usr/local/Cellar/gnu/11.0.0/bin/gfortran random_init.f90
% ./a.out
  0.731217086
  0.652637541
  0.381399393
  0.817764997
  0.394176722

% /usr/local/Cellar/gnu/11.0.0/bin/gfortran random_seed.f90
% ./a.out
  0.471070886
  0.117344737
  0.357547939
  0.318134785
  0.696753800

% /usr/local/Cellar/gnu/11.0.0/bin/gfortran --version
GNU Fortran (GCC) 11.0.0 20200804 (experimental)


More information about the Fortran mailing list