9.214. RAND

9.214 RAND — Real pseudo-random number

Description:
RAND(FLAG) returns a pseudo-random number from a uniform distribution between 0 and 1. If FLAG is 0, the next number in the current sequence is returned; if FLAG is 1, the generator is restarted by CALL SRAND(0); if FLAG has any other value, it is used as a new seed with SRAND.

This intrinsic routine is provided for backwards compatibility with GNU Fortran 77. It implements a simple modulo generator as provided by g77. For new code, one should consider the use of RANDOM_NUMBER as it implements a superior algorithm.

Standard:
GNU extension
Class:
Function
Syntax:
RESULT = RAND(I)
Arguments:
I Shall be a scalar INTEGER of kind 4.
Return value:
The return value is of REAL type and the default kind.
Example:
program test_rand
  integer,parameter :: seed = 86456

  call srand(seed)
  print *, rand(), rand(), rand(), rand()
  print *, rand(seed), rand(), rand(), rand()
end program test_rand
See also:
SRAND, RANDOM_NUMBER

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gfortran/RAND.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部