Go to main content
Oracle Developer Studio 12.5 Man Pages

Exit Print View

Updated: June 2017
 
 

ran(3F)

Name

ran - return a random number between 0 and 1

Synopsis

real function ran (i)
integer*4 i

Description

Repeated calls to ran generate random numbers with a uniform distribution.

Notes

See lcrans(3M).

The range includes 0.0 and excludes 1.0. The algorithm is a multiplicative, congruential type, general random number generator. In general, the value of i is set once during execution of the calling program. The initial value of i should be a large odd integer. Each call to ran returns the next random number in the sequence.

To get a different sequence of random numbers each time you run the calling program, you must set the argument i to a different initial value for each run.

Usage:

 
real  r, ran
integer*4 i
i = ...
     ...
r = ran(i)

Example:

demo% cat ran1.f
* ran1.f         <-- Generate random numbers
    integer*4 i, n
    real r(10)
    i = 760013
    do n = 1, 10
         r(n) = ran ( i )
    end do
    write ( *, "( 5 f11.6 )" ) r
    end
demo% f77 -silent ran1.f
demo% a.out
   0.222058 0.299851 0.390777 0.607055 0.653188
   0.060174 0.149466 0.444353 0.002982 0.976519
demo%

Files

libfsu.a

See Also

lcrans, addrans, and shufrans in the Numerical Computation Guide