consider the following program
program random
implicit none
 real :: x
 call random_seed();
 call random_number(x);
 write(*,*) x
end program random

When I run this program, I want to output different random numbers for
each run. This does not happen with gfortran.

$gfortran random.f90

$./a.out
 0.1264991

$./a.out
 0.1264991

$./a.out
 0.1264991

I agree that the current gfortran's behaviour is standard conforming. But it is
counter intuitive. Most of the other compilers (see below) do not exhibit this
behaviour. It would be nice if this functionality is provided by gfortran also.

I tried intel compiler (ifort 8.1). It does what I want to
do.

$ifort random.f90

$./a.out
 0.3770227

$./a.out
 0.7290102

$./a.out
 8.0997661E-02

$./a.out
 0.1369602

This is what I get with g95 (2005 Sep 13) build.

% ./a.out
 0.5556493
% ./a.out
 0.3600861
% ./a.out
 0.7311671
% ./a.out
 0.3920767

Absoft 8.0 exhibits this behaviour

% f90 random.f90
% ./a.out
   0.139087
% ./a.out
   0.139087
% ./a.out
   0.139087
% ./a.out
   0.139087


So absoft, intel, g95 compilers generate different sequences on subsequent runs.
 I hope gfortran also uses this methodology just to be consistent with the
common practice if not for anything else.

-- 
           Summary: non intuitive behaviour of gfortran
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kamaraju at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23889

Reply via email to