rand
and srand
are not standard Fortran functions. I expect your compiler documentation can tell you how best to use them. However the Fortran standard defines a subroutine random_seed
with three optional arguments (named save
, put
and get
). put
and get
are for setting and getting the random seed. save
can be used to return the size of integer array used to hold the seed for the PRNG. The generator can then be called with the standard routine random_number
.
Saving the current seed in a Fortran random number sequence
Question
I am currently using the intrinsic function rand()
to generate random numbers. I initialized my sequence with some defined seed, but I want to be able to output the current seed that rand()
is using at some point in my loop.
By doing this, I should be able to "continue" the sequence of random numbers in a new program.
From what I have seen online, there is no way to do this with the random number generator associated with rand()
and srand()
functions. Is this true? Can anyone suggest a different method (perhaps, RANDOM_NUMBER()
?).
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow