インテル® Fortran コンパイラー XE 13.1 ユーザー・リファレンス・ガイド

RAND, RANDOM

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

Module

USE IFPORT

result = RAND ([ iflag])

result = RANDOM (iflag)

iflag

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

結果

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.

RANDOM is available as a function or subroutine.

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

関連情報


このヘルプトピックについてのフィードバックを送信