Here is a simple test of random_number using two Fortran compilers I use.
These tests indicate:
The returned value is in the range ( 0 <= random_number(x) < 1 )
Silverfrost FTN95 is a reproduceable sequence, while
Gfortran 15.1.0 uses a different starting value ( for the compile options I used)
For my Monte-Carlo simulations I mostly used a reproduceable sequence.
implicit none
integer :: n,k,i
real*4 :: x, mi_x, ma_x
open (unit=11, file='random.log', position='append')
write (11,*) 'Vern : ',compiler_version ()
write (11,*) 'Opts : ',compiler_options ()
n = 2
mi_x = 1
ma_x = 0
do k = 1,24
do i = 1,n
call random_number (x)
if ( x == 0. ) write (11,*) 'zero detected', i
if ( x == 1. ) write (11,*) 'one detected', i
if ( x > ma_x ) ma_x = x
if ( x < mi_x ) mi_x = x
end do
write (11,fmt='(i8,2g18.8)') n,mi_x, ma_x
n = n*2
end do
end
Vern : FTN95 v9.20
Opts : 64;CHECKMATE;ECHO_OPTIONS;ERROR_NUMBERS;IMPLICIT_NONE;INTL;LINK;LOGL;NO_BANNER;UNLIMITED_ERRORS;VS7;
2 0.33098495 0.67307037
4 0.89860201E-01 0.74144781
8 0.55308938E-02 0.75059688
16 0.55308938E-02 0.93005449
32 0.55308938E-02 0.98703653
64 0.55308938E-02 0.98703653
128 0.55308938E-02 0.99690789
256 0.11609793E-02 0.99690789
512 0.10038018E-02 0.99690789
1024 0.78243017E-03 0.99844843
2048 0.78243017E-03 0.99930221
4096 0.16486645E-03 0.99948233
8192 0.69141388E-04 0.99998528
16384 0.28550625E-04 0.99998528
32768 0.97155571E-05 0.99998528
65536 0.35762787E-05 0.99999893
131072 0.35762787E-05 0.99999893
262144 0.35762787E-05 0.99999952
524288 0.11920929E-06 0.99999952
1048576 0.11920929E-06 0.99999952
2097152 0.11920929E-06 0.99999958
4194304 0.11920929E-06 0.99999970
zero detected 7634751
8388608 0.0000000 0.99999988
zero detected 2906636
16777216 0.0000000 0.99999994
Vern : GCC version 15.1.0
Opts : -cpp -iprefix C:/Program Files (x86)/gcc_eq/gcc_15.1.0/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/ -U_REENTRANT -mtune=generic -march=x86-64 -fno-underscoring -fdollar-ok
2 0.48348904E-02 0.69568729
4 0.48348904E-02 0.79884946
8 0.48348904E-02 0.85110766
16 0.59008598E-04 0.92572713
32 0.59008598E-04 0.95438445
64 0.59008598E-04 0.99653119
128 0.59008598E-04 0.99690586
256 0.59008598E-04 0.99839717
512 0.59008598E-04 0.99957311
1024 0.59008598E-04 0.99957311
2048 0.59008598E-04 0.99957311
4096 0.59008598E-04 0.99957311
8192 0.55015087E-04 0.99961603
16384 0.30994415E-05 0.99991792
32768 0.30994415E-05 0.99993944
65536 0.30994415E-05 0.99999046
131072 0.16093254E-05 0.99999100
262144 0.16093254E-05 0.99999577
524288 0.16093254E-05 0.99999577
1048576 0.95367432E-06 0.99999845
2097152 0.59604645E-06 0.99999887
zero detected 3443890
4194304 0.0000000 0.99999952
8388608 0.0000000 0.99999994
zero detected 811674
zero detected 4808671
16777216 0.0000000 0.99999994
Vern : FTN95 v9.20
Opts : 64;CHECKMATE;ECHO_OPTIONS;ERROR_NUMBERS;IMPLICIT_NONE;INTL;LINK;LOGL;NO_BANNER;UNLIMITED_ERRORS;VS7;
2 0.33098495 0.67307037
4 0.89860201E-01 0.74144781
8 0.55308938E-02 0.75059688
16 0.55308938E-02 0.93005449
32 0.55308938E-02 0.98703653
64 0.55308938E-02 0.98703653
128 0.55308938E-02 0.99690789
256 0.11609793E-02 0.99690789
512 0.10038018E-02 0.99690789
1024 0.78243017E-03 0.99844843
2048 0.78243017E-03 0.99930221
4096 0.16486645E-03 0.99948233
8192 0.69141388E-04 0.99998528
16384 0.28550625E-04 0.99998528
32768 0.97155571E-05 0.99998528
65536 0.35762787E-05 0.99999893
131072 0.35762787E-05 0.99999893
262144 0.35762787E-05 0.99999952
524288 0.11920929E-06 0.99999952
1048576 0.11920929E-06 0.99999952
2097152 0.11920929E-06 0.99999958
4194304 0.11920929E-06 0.99999970
zero detected 7634751
8388608 0.0000000 0.99999988
zero detected 2906636
16777216 0.0000000 0.99999994
Vern : GCC version 15.1.0
Opts : -cpp -iprefix C:/Program Files (x86)/gcc_eq/gcc_15.1.0/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/ -U_REENTRANT -mtune=generic -march=x86-64 -fno-underscoring -fdollar-ok
2 0.67090213E-01 0.50203764
4 0.40025771E-01 0.96130651
8 0.11717677E-01 0.96130651
16 0.11717677E-01 0.96130651
32 0.11717677E-01 0.99553567
64 0.11436999E-01 0.99949199
128 0.55414438E-02 0.99949199
256 0.34532547E-02 0.99949199
512 0.21323562E-02 0.99949199
1024 0.45263767E-03 0.99949199
2048 0.40495396E-03 0.99982810
4096 0.33193827E-03 0.99982810
8192 0.63836575E-04 0.99998480
16384 0.39398670E-04 0.99998719
32768 0.14841557E-04 0.99999207
65536 0.71525574E-05 0.99999207
131072 0.11920929E-06 0.99999797
262144 0.11920929E-06 0.99999797
524288 0.11920929E-06 0.99999964
zero detected 859344
1048576 0.0000000 0.99999964
2097152 0.0000000 0.99999964
4194304 0.0000000 0.99999982
8388608 0.0000000 0.99999994
zero detected 3340268
16777216 0.0000000 0.99999994