Skip to content

PRT062 gfortran-random-extension ​

warning opt-in

The extensions rand, srand, irand generate random numbers.

Why ​

rand/srand/irand are GNU extensions with a poor generator. The standard random_number and random_seed (or random_init, Fortran 2018) are portable.

Reported ​

fortran
x = rand()

Preferred ​

fortran
call random_number(x)

Suppressing ​

For one occurrence, with the reason on the same line (or alone on the line before the statement):

fortran
! fobis: ignore[PRT062] <why this occurrence is fine>

For the whole project, ignore = PRT062 in the fobos [lint] section.

Equivalent ​

Fortitude rule PORT062 (see Lint Rules).