Visible to Intel only — GUID: GUID-61D1EF6B-E344-488B-8BD3-4F805B7FB06B
Visible to Intel only — GUID: GUID-61D1EF6B-E344-488B-8BD3-4F805B7FB06B
DRAND, DRANDM
Portability Functions: Return double-precision random numbers in the range 0.0 to 1.0, not including the end points.
Module
USE IFPORT
result = DRAND (iflag)
result = DRANDM (iflag)
iflag |
(Input) INTEGER(4). Controls the way the random number is selected. |
Results
The result type is REAL(8). DRAND and DRANDM return random numbers in the range 0.0 to 1.0, not including the end points.
Value of iflag |
Selection process |
---|---|
1 |
The generator is restarted and the first random value is selected. |
0 |
The next random number in the sequence is selected. |
Otherwise |
The generator is reseeded using iflag, then restarted, and the first random value is selected. |
There is no difference between DRAND and DRANDM. Both functions are included to insure portability of existing code that references one or both of them.
The intrinsic subroutines RANDOM_INIT, RANDOM_NUMBER, and RANDOM_SEED provide the same functionality and they are the recommended functions to use when writing programs to generate random numbers.
Example
USE IFPORT
REAL(8) num
INTEGER(4) f
f=1
CALL print_rand
f=0
CALL print_rand
f=22
CALL print_rand
CONTAINS
SUBROUTINE print_rand
num = drand(f)
print *, 'f= ',f,':',num
END SUBROUTINE
END