Intel® Fortran Compiler 18.0 Developer Guide and Reference

RANDOM Subroutine

Portability Subroutine: Returns a pseudorandom number greater than or equal to zero and less than one from the uniform distribution.

Module

USE IFPORT

CALL RANDOM (ranval)

ranval

(Output) REAL(4). Pseudorandom number, 0 ranval< 1, from the uniform distribution.

A given seed always produces the same sequence of values from RANDOM.

If SEED is not called before the first call to RANDOM, RANDOM begins with a seed value of one. If a program must have a different pseudorandom sequence each time it runs, pass the constant RND$TIMESEED (defined in IFCORE.F90) to SEED before the first call to RANDOM.

The portability routines DRAND, DRANDM, IRAND, IRANDM, RAN, RAND, and the RANDOM portability function and subroutine use the same algorithms and thus return the same answers. They are all compatible and can be used interchangeably. The algorithm used is a "Prime Modulus M Multiplicative Linear Congruential Generator," a modified version of the random number generator by Park and Miller in "Random Number Generators: Good Ones Are Hard to Find," CACM, October 1988, Vol. 31, No. 10.

Example

 USE IFPORT
 REAL(4) ran

 CALL SEED(1995)
 CALL RANDOM(ran)

The following example shows how to use both the RANDOM subroutine and the RANDOM function:

use ifport
real(4) ranval
! from libifcore.lib
call seed(1995)     ! initialize
! also from for_m_irand.c in libfor
call random(ranval) ! get next random number

print *,ranval
! from libifport.lib
ranval = random(1)  ! initialize
! same
ranval = random(0)  ! get next random number

print *,ranval
end

See Also