RAND, RANDOM

Portability Functions: Return real random numbers in the range 0.0 through 1.0.

Module: USE IFPORT

Syntax

result = RAND ([ iflag ])
result = RANDOM (iflag)


iflag
(Input) INTEGER(4). Optional for RAND. Controls the way the random number is selected.


Results

The result type is REAL(4). RAND and RANDOM return random numbers in the range 0.0 through 1.0.

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, restarted, and the first random value is selected.

When RAND is called without an argument, iflag is assumed to be 0.

There is no difference between RAND and RANDOM. Both functions are included to ensure portability of existing code that references one or both of them. The intrinsic functions RANDOM_NUMBER and RANDOM_SEED provide the same functionality.

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

Note

RANDOM is available as a function or subroutine.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also

RANDOM_NUMBER, RANDOM_SEED, SRAND

Example

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

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