G05SBF (PDF version)
G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG05SBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G05SBF generates a vector of pseudorandom numbers taken from a beta distribution with parameters a and b.

## 2  Specification

 SUBROUTINE G05SBF ( N, A, B, STATE, X, IFAIL)
 INTEGER N, STATE(*), IFAIL REAL (KIND=nag_wp) A, B, X(N)

## 3  Description

The beta distribution has PDF (probability density function)
 fx = Γa+b Γa Γb xa-1 1-x b-1 if  0≤x≤1 ; ​ a,b>0 , fx=0 otherwise.
One of four algorithms is used to generate the variates depending on the values of a and b. Let α be the maximum and β be the minimum of a and b. Then the algorithms are as follows:
 (i) if α<0.5, Johnk's algorithm is used, see for example Dagpunar (1988). This generates the beta variate as u11/a/ u11/a+u21/b , where u1 and u2 are uniformly distributed random variates; (ii) if β>1, the algorithm BB given by Cheng (1978) is used. This involves the generation of an observation from a beta distribution of the second kind by the envelope rejection method using a log-logistic target distribution and then transforming it to a beta variate; (iii) if α>1 and β<1, the switching algorithm given by Atkinson (1979) is used. The two target distributions used are f1x=βxβ and f2x=α1-xβ-1, along with the approximation to the switching parameter of t=1-β/α+1-β; (iv) in all other cases, Cheng's BC algorithm (see Cheng (1978)) is used with modifications suggested by Dagpunar (1988). This algorithm is similar to BB, used when β>1, but is tuned for small values of a and b.
One of the initialization routines G05KFF (for a repeatable sequence if computed sequentially) or G05KGF (for a non-repeatable sequence) must be called prior to the first call to G05SBF.