mercredi 21 octobre 2020

Behaviour of random_number across different platforms [duplicate]

Here is a program I'm using to generate random numbers:

program randtest
    implicit none

    real rands(5)

    call random_number(rands)
    print*, rands

end program randtest

Note that I'm not initializing with a seed using random_seed as that is my intention. What I've learnt about pseudo-random number generators, like the one Fortran uses is that they start at a seed value which is either provided or chosen by default. So if the seed is not changed, the sequence of random numbers produced remains the same.

However, when I run this code on two different platforms using gfortran, I see different behaviour.

  • On Ubuntu 18.04 LTS, it generates a different sequence of numbers each time I run the compiled code.
  • On Windows 10 (MinGW), it generates the same sequence no matter how many times I run it.

Any insight about why this happens? Is it because in Ubuntu, somehow a different seed is chosen by default on each run? If so, why, when both are compiled using gfortran?




Aucun commentaire:

Enregistrer un commentaire