Fortran random seed initialization
Fortran 2018 specifies a new subroutine random_init().
Gfortran 9 and Intel oneAPI support random_init.
Build systems such as Meson and CMake can detect compiler capabilities. random/ folder full example
Meson standard random_init detection:
project('foo', ['fortran'])
fc = meson.get_compiler('fortran')
f18random = fc.compiles('''program test
implicit none
intrinsic :: random_init
call random_init(.false., .false.)
end''',
name: 'F2018 random_init')CMake standard random_init detection:
include(CheckSourceCompiles)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# save link time, only compile is needed
check_source_compiles(Fortran "program test
implicit none
intrinsic :: random_init
call random_init(.false., .false.)
end"
f18random)Older versions of gfortran call random_seed() gives a unique seed.
Not every compiler vendor gives a unique seed for random_seed() however.