I use gfortran fortran compiler at home and intel fortran compiler in office.
Its by random chance I found a vital difference in gfortran and intel compiler’s interpretation of using the intrinsic subroutine Random_number.
In gg95 fortran forum, someone posted this query.
I have the following code to generate a random number in between 0 and 1.
real :: R
But it always returns a same number. Why this happens, can any body suggest me?
I checked this in gfortran and I got the same result. Everytime it returned the same random number.
With Intel compiler the result was as expected. In sun solaris it was as expected. The program gave different random number on each call.
But gfortran was different. I thought it was a bug in gfortran.
But then Tobius Burnus explained this
No, it’s actually a bug in the Fortran standard: The standard does not
specify whether calling “random_number()” should produce by default the same sequence or every time a different sequence.
There are proponents for both.
One group argues that having a random_number() function should produce random results. Others argue that when running, e.g., an Monte Carlo algorithm, by default the results should be reproducible. As the standard does not mandate either choice, one has to live with having compiles in both groups. (I heard that the person responsible for adding the intrinsic believed that he had
written down the choice – but obviously he hasn’t.)
I think its worth keeping in mind. This can help solve lot of pain if you are using gfortran and intel compilers for your stochastic programs.