Next: RANGE, Previous: RADIX, Up: Intrinsic Procedures

`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`

.*Option*:- gnu
*Class*:- non-elemental function
*Syntax*:`X = RAND(FLAG)`

*Arguments*:-
`FLAG`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

*Note*:- For compatibility with HP FORTRAN 77/iX, the
`RAN`

intrinsic is provided as an alias for`RAND`

.