Non-repeating pseudorandom sequences in Fortran |
|
The first value returned by function rand(0) in the
execution of your program will always be the same. Also, the
sequence of numbers generated by rand(0) is cyclic.
If you call it enough times, you will eventually get a number
you've gotten before.
If you want your program to generate a different sequence of
pseudorandom numbers each time it is run, though, you can
call the rand() function with a nonzero argument,
and you will get a different number back.
In practice, a good way to get a different starting number each
time is call rand() with an argument that is a
function of the current time. For example, you could use
the Fortran itime subroutine (see the
man page for itime).