Random_Gamma Routines
Function generates a Random Gamma Variate.

Unit
QESBPCSRandom

Overloaded Variants
Function Random_Gamma(const Shape: Extended): Extended;
Function Random_Gamma(const Shape: Extended; RandomGenerator: TRandomGenFunction): Extended;

Declaration
Function Random_Gamma(const Shape: Extended): Extended;

Description
Adapted from Fortran 77 code from the book: Dagpunar, J. 'Principles of random variate generation' Clarendon Press, Oxford, 1988. ISBN 0-19-852202-9

Calls either random_gamma1 (Shape > 1.0)

OR random_exponential (Shape = 1.0)

OR random_gamma2 (Shape < 1.0).

Parameters
Shape Shape Parameter of Distribution - must be Positive.
RandomGenerator Optional Function to use for Uniform Random Number Generator. If omitted, Delphi's Random function is used, and if this is done remember to call Randomize if you don't want repeated values.

Category
Arithmetic Routines for Floats

Implementation

function Random_Gamma (const Shape: Extended): Extended;
begin
     Result := Random_Gamma (Shape, DelphiRandom);
End;

Declaration
Function Random_Gamma(const Shape: Extended; RandomGenerator: TRandomGenFunction): Extended;

Implementation

function Random_Gamma (const Shape: Extended;
     RandomGenerator: TRandomGenFunction): Extended;
begin
     if (Shape <= 0.0) then
          raise EMathError.Create (rsInvalidShape);

     if (Shape > 1.0) then
          Result := Random_Gamma1 (Shape, RandomGenerator)
     else if (Shape < 1.0) then
          Result := Random_Gamma2 (Shape, RandomGenerator)
     else
          Result := Random_Exponential (RandomGenerator);
End;


HTML generated by Time2HELP
http://www.time2help.com