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, the following applies:

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 iconNote

RANDOM is available as a function or subroutine.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

Example

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

use ifport
real(4) ranval 
call seed(1995) ! initialize 
call random(ranval) ! get next random number 
print *,ranval 


ranval = random(1) ! initialize 
ranval = random(0) ! get next random number 

print *,ranval 
end

See Also


Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.