Based on what I understood from the description of RANDOM_SEED Subroutine here, https://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html
I tried to get an array of size n by taking n as an input argument. However, I always get array of a fixed size (n = 32) no matter what I input in the argument of the executable. What am I doing wrong?
program test_random_seed
implicit none
integer, allocatable :: seed(:)
integer :: n
Character(len=2) :: inputnum
call GETARG(1, inputnum)
read (inputnum, *) n
call random_seed(size = n)
allocate(seed(n))
call random_seed(get=seed)
write (*, *) seed
deallocate(seed)
end program test_random_seed
Outputs:
./test_random_seed.out 6
270997589 -288181887 1948167863 -899467666 856399949 -616956193 -393084398 -169799794 -2106914961 -1327699024 -611308309 -956136276 -1047101846 1405583576 -2030082380 1642309723 -964872898 -478908624 486119102 1947066547 -722265400 -268681072 366932413 -791652926 1961977905 -349345081 465186042 808162632 -129440729 -683435376 1183730510 264749721 0
./tes_trandom_seed.out 4
911554020 -223715509 -703604837 -1861804415 1952830407 -1126364511 -1115643071 -1251893035 1013863844 1767892501 1999133695 -1456139371 -1813327006 1135316397 -2034112324 -1863710425 749654783 1021195219 1479800515 882047462 -1297200646 1932542969 -1428989180 1078641551 -431962594 -1403398736 620407660 472937510 1677653929 1187629179 -357974360 953325445 0
Aucun commentaire:
Enregistrer un commentaire