Next / Previous / Index / TCC Help System / Publications / Site map / NM Tech homepage

Non-repeating pseudorandom sequences in Fortran

Tech Computer Center logo

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).


Next: Scaling random numbers in Fortran
See also: Generating random numbers in Fortran; Hints for Fortran programmers
Previous: Repeatable pseudorandom sequences in Fortran
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Computer Center: Help System
TCC Publications
Home: About New Mexico Tech

John Shipman, john@nmt.edu

Last updated: 1995/12/19 18:58:09 UT
URL: http://www.nmt.edu/tcc/help/lang/fortran/seed.html