RNCHY
Generates pseudorandom numbers from a Cauchy distribution.
Required Arguments
R — Vector of length NR containing the random Cauchy deviates. (Output)
Optional Arguments
NR — Number of random numbers to generate. (Input)
Default: NR = size (R,1).
FORTRAN 90 Interface
Generic: CALL RNCHY (R [])
Specific: The specific interface names are S_RNCHY and D_RNCHY.
FORTRAN 77 Interface
Single: CALL RNCHY (NR, R)
Double: The double precision name is DRNCHY.
Description
Routine RNCHY generates pseudorandom numbers from a standard Cauchy distribution. The probability density function is
Use of the inverse CDF technique would yield a Cauchy deviate from a uniform (0, 1) deviate, u, as tan[π(u  5)]. Rather than evaluating a tangent directly, however, RNCHY generates two uniform (1, 1) deviates, x1 and x2. These values can be thought of as sine and cosine values. If
is less than or equal to 1, then x1/x2 is delivered as the Cauchy deviate; otherwise, x1 and x2 are rejected and two new uniform (–1, 1) deviates are generated. This method is also equivalent to taking the ratio of two independent normal deviates.
Deviates from the Cauchy distribution with median T and first quartile T  S, that is, with density
can be obtained by scaling the output from RNCHY. The following statements (in single precision) would yield random deviates from this Cauchy distribution.
 
CALL RNCHY (NR, R)
CALL SSCAL (NR, S, R, 1)
CALL SADD (NR, T, R, 1)
The Cauchy distribution is a member of the symmetric stable family of distributions. The routine RNSTA can be used to generate deviates from this more general family of distributions or even from the stable family not requiring symmetry.
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, RNCHY is used to generate five pseudorandom deviates from a Cauchy distribution.
 
USE RNCHY_INT
USE UMACH_INT
USE RNSET_INT
 
IMPLICIT NONE
INTEGER ISEED, NOUT, NR
REAL R(5)
!
CALL UMACH (2, NOUT)
NR = 5
ISEED = 123457
CALL RNSET (ISEED)
CALL RNCHY (R)
WRITE (NOUT,99999) R
99999 FORMAT (' Cauchy random deviates: ', 5F8.4)
END
Output
 
Cauchy random deviates: 3.5765 0.9353 15.5797 2.0815 -0.1333