Search code examples
fortrangfortranprngfortran-common-block

random number generator in fortran


I am testing the RNG code as mentioned in link (fortran 77 code):
https://www.cisl.ucar.edu/zine/96/spring/articles/3.random-6.html
which applies the Park & Miller algorithm.

the function call of the program is

call srand(seed)  
x=rand()  

However the program does not seem to respond to the seeding by srand(), i.e., the x-value is unaffected by the initial seeding, and always equal to ~0.218. I suspect that this has to do with the definition of the common block and data block, as the value of x is equivalent to putting the seed as 123456789, which is the initialization value defined in the datablock.

Any ideas?

I am compiling with gfortran.


Solution

  • Ok, the problem is that the original srand and rand may be called. I renamed functions to srand2 and rand2 and everything start to work as expected.

    For seed = 1 the result is 7.82636926E-06 and for seed = 2 the result is 1.56527385E-05. Checked it in gfortran and in Intel's fortran.