Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

different random number each time

csliu
Beginner
797 Views
I read the topic about random number posted previously.
As the Fortran's help files said, I referred RND$TIMESEED as the argument of the seed, I can get the different random number seqences each time.

PROGRAM temp
USE DFLIB
REAL rand
CALL SEED(RND$TIMESEED)
CALL RANDOM(rand)
print *, "random =", rand
END PROGRAM temp

Now, I meet the new problem
How can I get diffent seed for other random number generator each time, like ran2(idum) in Numerical Recipes in Fortran?
0 Kudos
2 Replies
TimP
Honored Contributor III
797 Views
The usual method for getting different sequences from RNG code, where source is provided, is to set the seed(s) from contents of the DATE_AND_TIME VALUES array, elements (5:8). Looks like that could be consistent. However, you might use RANDOM_SEED() and RANDOM_NUMBER(). The usual reason for using the Numerical Recipes functions would be to get the same sequences on different compilers, or possibly a quicker but less rigorous sequence than Fortran's own library.
0 Kudos
kdkeefer
Beginner
797 Views
Tim,
FYI, the authors of NR for Fortran, 2nd Ed. offer a $1000 reward for anyone who can demonstrate that RAN2 fails any test in a non-trivial way :).
Keith
0 Kudos
Reply