rand returns real values in the range 0.0 through 1.0.
drand returns double precision values in the range 0.0 through 1.0.
irand returns positive integers in the range 0 through 2147483647.
These functions use random(3) to generate sequences of random numbers. The three functions share the same 256 byte state array. The only advantage of these functions is that they are widely available on UNIX systems. For better random number generators, compare lcrans, addrans, and shufrans. See also random(3), and the Numerical Computation Guide
i = irand( k ) r = rand( k ) d = drand( k ) |
|||
k |
INTEGER*4 |
Input |
k=0: Get next random number in the sequence k=1: Restart sequence, return first number k>0: Use as a seed for new sequence, return first number |
rand |
REAL*4 |
Output | |
drand |
REAL*8 |
Output | |
irand |
INTEGER*4 |
Output |
Example: irand():
demo% cat trand.f integer*4 v(5), iflag/0/ do i = 1, 5 v(i) = irand( iflag ) end do write(*,*) v end demo% f95 trand.f demo% a.out 2078917053 143302914 1027100827 1953210302 755253631 demo% |