# Gamma

Generates gamma distributed random values.

## Syntax

Fortran:

status = vsrnggamma( method, stream, n, r, alpha, a, beta )

status = vdrnggamma( method, stream, n, r, alpha, a, beta )

C:

status = vsRngGamma( method, stream, n, r, alpha, a, beta );

status = vdRngGamma( method, stream, n, r, alpha, a, beta );

## Description

This function generates random numbers with gamma distribution that has shape parameter α, displacement a, and scale parameter β, where α, β, and `a∈R ; α > 0, β > 0`.

The probability density function is given by:

where Γ(α) is the complete gamma function.

The cumulative distribution function is as follows:

## Input Parameters

Name | Type | Description
--- | --- | ---
method | FORTRAN: INTEGER, INTENT(IN) C: int | Generation method. The specific values are as follows: `VSL_METHOD_SGAMMA_GNORM` `VSL_METHOD_DGAMMA_GNORM` `VSL_METHOD_SGAMMA_GNORM_ACCURATE` `VSL_METHOD_DGAMMA_GNORM_ACCURATE` Acceptance/rejection method using random numbers with Gaussian distribution. See brief description of the method GNORM in Table“Values of `<method>` in method parameter”
stream | FORTRAN: TYPE (VSL_STREAM_STATE), INTENT(IN) C: VSLStreamStatePtr | FORTRAN: Descriptor of the stream state structure C: Pointer to the stream state structure
n | FORTRAN: INTEGER, INTENT(IN) C: int | Number of random values to be generated
alpha | FORTRAN: REAL, INTENT(IN) for vsrnggamma DOUBLE PRECISION, INTENT(IN) for vdrnggamma C: float for vsRngGamma double for vdRngGamma | Shape α .
a | FORTRAN: REAL, INTENT(IN) for vsrnggamma DOUBLE PRECISION, INTENT(IN) for vdrnggamma C: float for vsRngGamma double for vdRngGamma | Displacement a.
beta | FORTRAN: REAL, INTENT(IN) for vsrnggamma DOUBLE PRECISION, INTENT(IN) for vdrnggamma C: float for vsRngGamma double for vdRngGamma | Scalefactor β.

## Output Parameters

Name | Type | Description
--- | --- | ---
r | FORTRAN: REAL, INTENT(OUT) for vsrnggamma DOUBLE PRECISION, INTENT(OUT) for vdrnggamma C: float* for vsRngGamma double* for vdRngGamma | Vector of n random numbers with gamma distribution

## Return Values

VSL_ERROR_OK, VSL_STATUS_OK
  Indicates no error, execution is successful.
VSL_ERROR_NULL_PTR
  stream is a NULL pointer.
VSL_ERROR_BAD_STREAM

  stream is not a valid random stream.

VSL_ERROR_BAD_UPDATE

  Callback function for an abstract BRNG returns an invalid number of updated entries in a buffer, that is, `< 0` or `> nmax`.

VSL_ERROR_NO_NUMBERS

  Callback function for an abstract BRNG returns 0 as the number of updated entries in a buffer.

Parent topic: Continuous Distributions