Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

IRAND, IRANDM

Portability Functions: Return random numbers in the range 0 through (2**31)-1, or 0 through (2**15)-1 if called without an argument.

Module

USE IFPORT

result = IRAND ([iflag])

result = IRANDM ([iflag])

iflag

(Input) INTEGER(4). Optional for IRAND. Controls the way the returned random number is chosen. If iflag is omitted, it is assumed to be 0, and the return range is 0 through (2**15)-1 (inclusive).

Results

The result type is INTEGER(4). If iflag is 1, the generator is restarted and the first random value is returned. If iflag is 0, the next random number in the sequence is returned. If iflag is neither zero nor 1, it is used as a new seed for the random number generator, and the functions return the first new random value.

IRAND and IRANDM are equivalent and return the same random numbers. Both functions are included to ensure portability of existing code that references one or both of them.

You can use SRAND to restart the pseudorandom number generator used by these functions.

Example

 USE IFPORT
 INTEGER(4) istat, flag_value, r_nums(20)
 flag_value=1
 r_nums(1) = IRAND (flag_value)
 flag_value=0
 do istat=2,20
    r_nums(istat) = irand(flag_value)
 end do