RNGEO
Generates pseudorandom numbers from a geometric distribution.
Required Arguments
P — Probability of success on each trial. (Input)
P must be positive and less than 1.0.
IR — Vector of length NR containing the random geometric deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (IR,1).
FORTRAN 90 Interface
Generic: CALL RNGEO (P, IR [])
Specific: The specific interface name is S_RNGEO.
FORTRAN 77 Interface
Single: CALL RNGEO (NR, P, IR)
Description
Routine RNGEO generates pseudorandom numbers from a geometric distribution with parameter P, where P is the probability of getting a success on any trial. A geometric deviate can be interpreted as the number of trials until the first success (including the trial in which the first success is obtained). The probability function is
f(x) = P(1 – P)x1
for x = 1, 2,  and 0 < P < 1
The geometric distribution as defined above has mean 1/P.
The i‑th geometric deviate is generated as the smallest integer not less than log(Ui)/log(1  P ), where the Ui are independent uniform (0, 1) random numbers (see Knuth, 1981).
The geometric distribution is often defined on 0, 1, 2, , with mean (1  P)/P. Such deviates can be obtained by subtracting 1 from each element of IR.
Comments
The 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.
Example
In this example, RNGEO is used to generate five pseudorandom deviates from a geometric distribution with parameter P equal to 0.3.
 
USE RNGEO_INT
USE UMACH_INT
USE RNSET_INT
 
IMPLICIT NONE
INTEGER NR
PARAMETER (NR=5)
!
INTEGER IR(NR), ISEED, NOUT
REAL P
!
CALL UMACH (2, NOUT)
P = 0.3
ISEED = 123457
CALL RNSET (ISEED)
CALL RNGEO (P, IR)
WRITE (NOUT,99999) IR
99999 FORMAT (' Geometric(0.3) random deviates: ', 5I8)
END
Output
 
Geometric(0.3) random deviates: 1 4 1 2 1