Integer overflow is prohibited by the Fortran standard. The behavior of gfortran on integer overflow is undefined by default. Traditional code, like linear congruential pseudo-random number generators in old programs that rely on specific, non-standard behavior may generate unexpected results. The -fsanitize=undefined option can be used to detect such code at runtime.
It is recommended to use the intrinsic subroutine RANDOM_NUMBER
for random number generators or, if the old behavior is desired, to
use the -fwrapv option. Note that this option can impact
performance.