## RANDGAMMA Generate Gamma-Distributed Random Variable

Section: Random Number Generation

### Usage

Generates random variables with a gamma distribution. The general syntax for its use is

       y = randgamma(a,r),

where `a` and `r` are vectors describing the parameters of the gamma distribution. Roughly speaking, if `a` is the mean time between changes of a Poisson random process, and we wait for the `r` change, the resulting wait time is Gamma distributed with parameters `a` and `r`.

### Function Internals

The Gamma distribution arises in Poisson random processes. It represents the waiting time to the occurance of the `r`-th event in a process with mean time `a` between events. The probability distribution of a Gamma random variable is

Note also that for integer values of `r` that a Gamma random variable is effectively the sum of `r` exponential random variables with parameter `a`.

### Example

Here we use the `randgamma` function to generate Gamma-distributed random variables, and then generate them again using the `randexp` function.

    --> randgamma(1,15*ones(1,9))
    ans =
      <float>  - size: [1 9]

    Columns 1 to 7
     22.780443  11.551359  16.853683  12.745702  16.230314  10.744172  19.394232

    Columns 8 to 9
     16.361151  17.477238
    --> sum(randexp(ones(15,9)))
    ans =
      <float>  - size: [1 9]

    Columns 1 to 6
     14.6404095  15.1859598  13.3146982  11.4380150   7.2307277  10.8224525

    Columns 7 to 9
     14.5270958  12.4630632  11.8753099