RNUNF
This function generates a pseudorandom number from a uniform (0, 1) distribution.
Function Return Value
RNUNF — Function value, a random uniform (0, 1) deviate. (Output)
See Comment 1.
Required Arguments
None
FORTRAN 90 Interface
Generic: RNUNF ()
Specific: The specific interface names are S_RNUNF and D_RNUNF.
FORTRAN 77 Interface
Single: RNUNF ()
Double: The double precision name is DRNUNF.
Description
Routine
RNUNF is the function form of
RNUN.
The routine RNUNF generates pseudorandom numbers from a uniform (0, 1) distribution. The algorithm used is determined by
RNOPT. The values returned by
RNUNF are positive and less than 1.0.
If several uniform deviates are needed, it may be more efficient to obtain them all at once by a call to RNUN rather than by several references to RNUNF.
Comments
1. If the generic version of this function is used, the immediate result must be stored in a variable before use in an expression. For example:
X = RNUNF(6)
Y = SQRT(X)
must be used rather than
Y = SQRT(RNUNF(6))
If this is too much of a restriction on the programmer, then the specific name can be used without this restriction.
2. Routine
RNSET can be used to initialize the seed of the random number generator. The routine
RNOPT can be used to select the form of the generator.
3. This function has a side effect: it changes the value of the seed, which is passed through a common block.
Example
In this example, RNUNF is used to generate five pseudorandom uniform numbers. Since RNOPT is not called, the generator used is a simple multiplicative congruential one with a multiplier of 16807.
USE RNUNF_INT
USE RNSET_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER I, ISEED, NOUT
REAL R(5)
!
CALL UMACH (2, NOUT)
ISEED = 123457
CALL RNSET (ISEED)
DO 10 I=1, 5
R(I) = RNUNF()
10 CONTINUE
WRITE (NOUT,99999) R
99999 FORMAT (' Uniform random deviates: ', 5F8.4)
END
Output
Uniform random deviates: 0.9662 0.2607 0.7663 0.5693 0.8448