---
name: "Math::GSL::Randist"
section: "3pm"
platform: "linux"
package: "libmath-gsl-perl"
version: "0.45-2+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Math::GSL::Randist"
---

# Math::GSL::Randist(3pm)

Probability Distributions

## NAME

Math::GSL::Randist - Probability Distributions

## SYNOPSIS

```
 use Math::GSL::RNG;
 use Math::GSL::Randist qw/:all/;
 my $rng = Math::GSL::RNG->new();
 my $coinflip = gsl_ran_bernoulli($rng->raw(), .5);
```

## DESCRIPTION

Here is a list of all the functions included in this module. For all sampling methods, the first argument `$r` is a raw gsl\_rnd structure retrieve by calling **raw()** on an Math::GSL::RNG object.

### Bernoulli

- gsl\_ran\_bernoulli($r, $p)

  This function returns either 0 or 1, the result of a Bernoulli trial with probability `$p`. The probability distribution for a Bernoulli trial is, p(0) = 1 - `$p` and  p(1) = `$p`. `$r` is a gsl\_rng structure.

- gsl\_ran\_bernoulli\_pdf($k, $p)

  This function computes the probability p($k) of obtaining `$k` from a Bernoulli distribution with probability parameter `$p`, using the formula given above.

### Beta

- gsl\_ran\_beta($r, $a, $b)

  This function returns a random variate from the beta distribution. The distribution function is, p($x) dx = {Gamma($a+$b) \\ Gamma($a) Gamma($b)} `$x`\*\*{$a-1} (1-$x)\*\*{$b-1} dx for 0 \<= `$x` \<= 1.$r is a gsl\_rng structure.

- gsl\_ran\_beta\_pdf($x, $a, $b)

  This function computes the probability density p($x) at `$x` for a beta distribution with parameters `$a` and `$b`, using the formula given above.

### Binomial

- gsl\_ran\_binomial($k, $p, $n)

  This function returns a random integer from the binomial distribution, the number of successes in n independent trials with probability `$p`. The probability distribution for binomial variates is p($k) = {$n! \\ `$k`! ($n-$k)! } `$p`\*\*$k (1-$p)^{$n-$k} for 0 \<= `$k` \<= `$n`. Uses Binomial Triangle Parallelogram Exponential algorithm.

- gsl\_ran\_binomial\_knuth($k, $p, $n)

  Alternative and original implementation for gsl\_ran\_binomial using Knuth's algorithm.

- gsl\_ran\_binomial\_tpe($k, $p, $n)

  Same as gsl\_ran\_binomial.

- gsl\_ran\_binomial\_pdf($k, $p, $n)

  This function computes the probability p($k) of obtaining `$k` from a binomial distribution with parameters `$p` and `$n`, using the formula given above.

### Exponential

- gsl\_ran\_exponential($r, $mu)

  This function returns a random variate from the exponential distribution with mean `$mu`. The distribution is, p($x) dx = {1 \\ `$mu`} exp(-$x/$mu) dx for `$x` \>= 0. `$r` is a gsl\_rng structure.

- gsl\_ran\_exponential\_pdf($x, $mu)

  This function computes the probability density p($x) at `$x` for an exponential distribution with mean `$mu`, using the formula given above.

### Exponential Power

- gsl\_ran\_exppow($r, $a, $b)

  This function returns a random variate from the exponential power distribution with scale parameter `$a` and exponent `$b`. The distribution is, p(x) dx = {1 / 2 `$a` Gamma(1+1/$b)} exp(-\|$x/$a\|\*\*$b) dx for `$x` \>= 0. For `$b` = 1 this reduces to the Laplace distribution. For `$b` = 2 it has the same form as a gaussian distribution, but with `$a` = **sqrt**(2) sigma. `$r` is a gsl\_rng structure.

- gsl\_ran\_exppow\_pdf($x, $a, $b)

  This function computes the probability density p($x) at `$x` for an exponential power distribution with scale parameter `$a` and exponent `$b`, using the formula given above.

### Cauchy

- gsl\_ran\_cauchy($r, $scale)

  This function returns a random variate from the Cauchy distribution with `$scale`. The probability distribution for Cauchy random variates is,

  ```
   p(x) dx = {1 / $scale pi (1 + (x/$$scale)**2) } dx
  ```

  for x in the range -infinity to +infinity.  The Cauchy distribution is also known as the Lorentz distribution. `$r` is a gsl\_rng structure.

- gsl\_ran\_cauchy\_pdf($x, $scale)

  This function computes the probability density p($x) at `$x` for a Cauchy distribution with `$scale`, using the formula given above.

### Chi-Squared

- gsl\_ran\_chisq($r, $nu)

  This function returns a random variate from the chi-squared distribution with `$nu` degrees of freedom. The distribution function is, p(x) dx = {1 / 2 Gamma($nu/2) } (x/2)\*\*{$nu/2 - 1} exp(-x/2) dx for `$x` \>= 0. `$r` is a gsl\_rng structure.

- gsl\_ran\_chisq\_pdf($x, $nu)

  This function computes the probability density p($x) at `$x` for a chi-squared distribution with `$nu` degrees of freedom, using the formula given above.

### Dirichlet

- gsl\_ran\_dirichlet($r, $alpha)

  This function returns an array of K (where K = length of `$alpha` array) random variates from a Dirichlet distribution of order K-1. The distribution function is

  ```
    p(\theta_1, ..., \theta_K) d\theta_1 ... d\theta_K =
       (1/Z) \prod_{i=1}^K \theta_i^{\alpha_i - 1} \delta(1 -\sum_{i=1}^K \theta_i) d\theta_1 ... d\theta_K
  ```

  for theta\_i \>= 0 and alpha\_i \> 0. The delta function ensures that \\sum \\theta\_i = 1. The normalization factor Z is

  ```
    Z = {\prod_{i=1}^K \Gamma(\alpha_i)} / {\Gamma( \sum_{i=1}^K \alpha_i)}
  ```

  The random variates are generated by sampling K values from gamma distributions with parameters a=alpha\_i, b=1, and renormalizing. See A.M. Law, W.D. Kelton, Simulation Modeling and Analysis (1991).

- gsl\_ran\_dirichlet\_pdf($theta, $alpha)

  This function computes the probability density p(\\theta\_1, ... , \\theta\_K) at theta\[K\] for a Dirichlet distribution with parameters alpha\[K\], using the formula given above. `$alpha` and `$theta` should be array references of the same size. Theta should be normalized to sum to 1.

- gsl\_ran\_dirichlet\_lnpdf($theta, $alpha)

  This function computes the logarithm of the probability density p(\\theta\_1, ... , \\theta\_K) for a Dirichlet distribution with parameters alpha\[K\]. `$alpha` and `$theta` should be array references of the same size. Theta should be normalized to sum to 1.

### Erlang

- gsl\_ran\_erlang($r, $scale, $shape)

  Equivalent to gsl\_ran\_gamma($r, `$shape`, `$scale`) where `$shape` is an integer.

- gsl\_ran\_erlang\_pdf

  Equivalent to gsl\_ran\_gamma\_pdf($r, `$shape`, `$scale`) where `$shape` is an integer.

### F-distribution

- gsl\_ran\_fdist($r, $nu1, $nu2)

  This function returns a random variate from the F-distribution with degrees of freedom nu1 and nu2. The distribution function is, p(x) dx = { Gamma(($nu\_1 + `$nu_2`)/2) / Gamma($nu\_1/2) Gamma($nu\_2/2) } `$nu_1`\*\*{$nu\_1/2} `$nu_2`\*\*{$nu\_2/2} x\*\*{$nu\_1/2 - 1} ($nu\_2 + `$nu_1` x)\*\*{-$nu\_1/2 -$nu\_2/2} for `$x` \>= 0. `$r` is a gsl\_rng structure.

- gsl\_ran\_fdist\_pdf($x, $nu1, $nu2)

  This function computes the probability density p(x) at x for an F-distribution with nu1 and nu2 degrees of freedom, using the formula given above.

### Uniform/Flat distribution

- gsl\_ran\_flat($r, $a, $b)

  This function returns a random variate from the flat (uniform) distribution from a to b. The distribution is, p(x) dx = {1 / ($b-$a)} dx if `$a` \<= x \< `$b` and 0 otherwise. `$r` is a gsl\_rng structure.

- gsl\_ran\_flat\_pdf($x, $a, $b)

  This function computes the probability density p($x) at `$x` for a uniform distribution from `$a` to `$b`, using the formula given above.

### Gamma

- gsl\_ran\_gamma($r, $shape, $scale)

  This function returns a random variate from the gamma distribution. The distribution function is,\
             p(x) dx = {1 \\over \\Gamma($shape) `$scale`^$shape} x^{$shape-1} e^{-x/$scale} dx for x \> 0. Uses Marsaglia-Tsang method. Can also be called as gsl\_ran\_gamma\_mt.

- gsl\_ran\_gamma\_pdf($x, $shape, $scale)

  This function computes the probability density p($x) at `$x` for a gamma distribution with parameters `$shape` and `$scale`, using the formula given above.

- gsl\_ran\_gamma($r, $shape, $scale)

  Same as gsl\_ran\_gamma.

- gsl\_ran\_gamma\_knuth($r, $shape, $scale)

  Alternative implementation for gsl\_ran\_gamma, using algorithm in Knuth volume 2.

### Gaussian/Normal

- gsl\_ran\_gaussian($r, $sigma)

  This function returns a Gaussian random variate, with mean zero and standard deviation `$sigma`. The probability distribution for Gaussian random variates is, p(x) dx = {1 / sqrt{2 pi `$sigma`\*\*2}} exp(-x\*\*2 / 2 `$sigma`\*\*2) dx for x in the range -infinity to +infinity. `$r` is a gsl\_rng structure. Uses Box-Mueller (polar) method.

- gsl\_ran\_gaussian\_ratio\_method($r, $sigma)

  This function computes a Gaussian random variate using the alternative Kinderman-Monahan-Leva ratio method.

- gsl\_ran\_gaussian\_ziggurat($r, $sigma)

  This function computes a Gaussian random variate using the alternative Marsaglia-Tsang ziggurat ratio method. The Ziggurat algorithm is the fastest available algorithm in most cases. `$r` is a gsl\_rng structure.

- gsl\_ran\_gaussian\_pdf($x, $sigma)

  This function computes the probability density p($x) at `$x` for a Gaussian distribution with standard deviation sigma, using the formula given above.

- gsl\_ran\_ugaussian($r)

  - gsl\_ran\_ugaussian\_ratio\_method($r)

  - gsl\_ran\_ugaussian\_pdf($x)

  This function computes results for the unit Gaussian distribution. It is equivalent to the gaussian functions above with a standard deviation of one, sigma = 1.

- gsl\_ran\_bivariate\_gaussian($r, $sigma\_x, $sigma\_y, $rho)

  This function generates a pair of correlated Gaussian variates, with mean zero, correlation coefficient rho and standard deviations `$sigma_x` and `$sigma_y` in the x and y directions. The first value returned is x and the second y. The probability distribution for bivariate Gaussian random variates is, p(x,y) dx dy = {1 / 2 pi `$sigma_x` `$sigma_y` sqrt{1-$rho\*\*2}} exp (-(x\*\*2/$sigma\_x\*\*2 + y\*\*2/$sigma\_y\*\*2 - 2 `$rho` x y/($sigma\_x `$sigma_y`))/2(1- `$rho`\*\*2)) dx dy for x,y in the range -infinity to +infinity. The correlation coefficient `$rho` should lie between 1 and -1. `$r` is a gsl\_rng structure.

- gsl\_ran\_bivariate\_gaussian\_pdf($x, $y, $sigma\_x, $sigma\_y, $rho)

  This function computes the probability density p($x,$y) at ($x,$y) for a bivariate Gaussian distribution with standard deviations `$sigma_x`, `$sigma_y` and correlation coefficient `$rho`, using the formula given above.

### Gaussian Tail

- gsl\_ran\_gaussian\_tail($r, $a, $sigma)

  This function provides random variates from the upper tail of a Gaussian distribution with standard deviation sigma. The values returned are larger than the lower limit a, which must be positive. The probability distribution for Gaussian tail random variates is, p(x) dx = {1 / N($a; `$sigma`) sqrt{2 pi sigma\*\*2}} exp(- x\*\*2/(2 sigma\*\*2)) dx for x \> `$a` where N($a; `$sigma`) is the normalization constant, N($a; `$sigma`) = (1/2) erfc($a / sqrt(2 `$sigma`\*\*2)). `$r` is a gsl\_rng structure.

- gsl\_ran\_gaussian\_tail\_pdf($x, $a, $gaussian)

  This function computes the probability density p($x) at `$x` for a Gaussian tail distribution with standard deviation sigma and lower limit `$a`, using the formula given above.

- gsl\_ran\_ugaussian\_tail($r, $a)

  This functions compute results for the tail of a unit Gaussian distribution. It is equivalent to the functions above with a standard deviation of one, `$sigma` = 1. `$r` is a gsl\_rng structure.

- gsl\_ran\_ugaussian\_tail\_pdf($x, $a)

  This functions compute results for the tail of a unit Gaussian distribution. It is equivalent to the functions above with a standard deviation of one, `$sigma` = 1.

### Landau

- gsl\_ran\_landau($r)

  This function returns a random variate from the Landau distribution. The probability distribution for Landau random variates is defined analytically by the complex integral, p(x) = (1/(2 \\pi i)) \\int\_{c-i\\infty}^{c+i\\infty} ds exp(s log(s) + x s) For numerical purposes it is more convenient to use the following equivalent form of the integral, p(x) = (1/\\pi) \\int\_0^\\infty dt \\exp(-t \\log(t) - x t) \\sin(\\pi t). `$r` is a gsl\_rng structure.

- gsl\_ran\_landau\_pdf($x)

  This function computes the probability density p($x) at `$x` for the Landau distribution using an approximation to the formula given above.

### Geometric

- gsl\_ran\_geometric($r, $p)

  This function returns a random integer from the geometric distribution, the number of independent trials with probability `$p` until the first success. The probability distribution for geometric variates is, p(k) =  p (1-$p)^(k-1) for k \>= 1. Note that the distribution begins with k=1 with this definition. There is another convention in which the exponent k-1 is replaced by k. `$r` is a gsl\_rng structure.

- gsl\_ran\_geometric\_pdf($k, $p)

  This function computes the probability p($k) of obtaining `$k` from a geometric distribution with probability parameter p, using the formula given above.

### Hypergeometric

- gsl\_ran\_hypergeometric($r, $n1, $n2, $t)

  This function returns a random integer from the hypergeometric distribution. The probability distribution for hypergeometric random variates is, p(k) =  C(n\_1, k) C(n\_2, t - k) / C(n\_1 + n\_2, t) where C(a,b) = a!/(b!(a-b)!) and t \<= n\_1 + n\_2. The domain of k is max(0,t-n\_2), ..., min(t,n\_1). If a population contains n\_1 elements of "type 1" and n\_2 elements of "type 2" then the hypergeometric distribution gives the probability of obtaining k elements of "type 1" in t samples from the population without replacement. `$r` is a gsl\_rng structure.

- gsl\_ran\_hypergeometric\_pdf($k, $n1, $n2, $t)

  This function computes the probability p(k) of obtaining k from a hypergeometric distribution with parameters `$n1`, `$n2` `$t`, using the formula given above.

### Gumbel

- gsl\_ran\_gumbel1($r, $a, $b)

  This function returns a random variate from the Type-1 Gumbel distribution. The Type-1 Gumbel distribution function is, p(x) dx = a b \\exp(-(b \\exp(-ax) + ax)) dx for -\\infty \< x \< \\infty. `$r` is a gsl\_rng structure.

- gsl\_ran\_gumbel1\_pdf($x, $a, $b)

  This function computes the probability density p($x) at `$x` for a Type-1 Gumbel distribution with parameters `$a` and `$b`, using the formula given above.

- gsl\_ran\_gumbel2($r, $a, $b)

  This function returns a random variate from the Type-2 Gumbel distribution. The Type-2 Gumbel distribution function is, p(x) dx = a b x^{-a-1} \\exp(-b x^{-a}) dx for 0 \< x \< \\infty. `$r` is a gsl\_rng structure.

- gsl\_ran\_gumbel2\_pdf($x, $a, $b)

  This function computes the probability density p($x) at `$x` for a Type-2 Gumbel distribution with parameters `$a` and `$b`, using the formula given above.

### Logistic

- gsl\_ran\_logistic($r, $a)

  This function returns a random variate from the logistic distribution. The distribution function is, p(x) dx = { \\exp(-x/a) \\over a (1 + \\exp(-x/a))^2 } dx for -\\infty \< x \< +\\infty. `$r` is a gsl\_rng structure.

- gsl\_ran\_logistic\_pdf($x, $a)

  This function computes the probability density p($x) at `$x` for a logistic distribution with scale parameter `$a`, using the formula given above.

### Lognormal

- gsl\_ran\_lognormal($r, $zeta, $sigma)

  This function returns a random variate from the lognormal distribution. The distribution function is, p(x) dx = {1 \\over x \\sqrt{2 \\pi \\sigma^2} } \\exp(-(\\ln(x) - \\zeta)^2/2 \\sigma^2) dx for x \> 0. `$r` is a gsl\_rng structure.

- gsl\_ran\_lognormal\_pdf($x, $zeta, $sigma)

  This function computes the probability density p($x) at `$x` for a lognormal distribution with parameters `$zeta` and `$sigma`, using the formula given above.

### Logarithmic

- gsl\_ran\_logarithmic($r, $p)

  This function returns a random integer from the logarithmic distribution. The probability distribution for logarithmic random variates is, p(k) = {-1 \\over \\log(1-p)} {(p^k \\over k)} for k \>= 1. `$r` is a gsl\_rng structure.

- gsl\_ran\_logarithmic\_pdf($k, $p)

  This function computes the probability p($k) of obtaining `$k` from a logarithmic distribution with probability parameter `$p`, using the formula given above.

### Multinomial

- gsl\_ran\_multinomial($r, $P, $N)

  This function computes and returns a random sample n\[\] from the multinomial distribution formed by N trials from an underlying distribution p\[K\]. The distribution function for n\[\] is,

  ```
   P(n_1, n_2, ..., n_K) =
      (N!/(n_1! n_2! ... n_K!)) p_1^n_1 p_2^n_2 ... p_K^n_K
  ```

  where (n\_1, n\_2, ..., n\_K) are nonnegative integers with sum\_{k=1}^K n\_k = N, and (p\_1, p\_2, ..., p\_K) is a probability distribution with \\sum p\_i = 1. If the array p\[K\] is not normalized then its entries will be treated as weights and normalized appropriately.

  Random variates are generated using the conditional binomial method (see C.S. Davis, The computer generation of multinomial random variates, Comp. Stat. Data Anal. 16 (1993) 205-217 for details).

- gsl\_ran\_multinomial\_pdf($counts, $P)

  This function returns the probability for the multinomial distribution P(counts\[1\], counts\[2\], ..., counts\[K\]) with parameters p\[K\].

- gsl\_ran\_multinomial\_lnpdf($counts, $P)

  This function returns the logarithm of the probability for the multinomial distribution P(counts\[1\], counts\[2\], ..., counts\[K\]) with parameters p\[K\].

### Negative Binomial

- gsl\_ran\_negative\_binomial($r, $p, $n)

  This function returns a random integer from the negative binomial distribution, the number of failures occurring before n successes in independent trials with probability p of success. The probability distribution for negative binomial variates is, p(k) = {\\Gamma(n + k) \\over \\Gamma(k+1) \\Gamma(n) } p^n (1-p)^k Note that n is not required to be an integer.

- gsl\_ran\_negative\_binomial\_pdf($k, $p, $n)

  This function computes the probability p($k) of obtaining `$k` from a negative binomial distribution with parameters `$p` and `$n`, using the formula given above.

### Pascal

- gsl\_ran\_pascal($r, $p, $n)

  This function returns a random integer from the Pascal distribution. The Pascal distribution is simply a negative binomial distribution with an integer value of `$n`. p($k) = {($n + `$k` - 1)! \\ `$k`! ($n - 1)! } `$p`\*\*$n (1-$p)\*\*$k for `$k` \>= 0. `$r` is gsl\_rng structure

- gsl\_ran\_pascal\_pdf($k, $p, $n)

  This function computes the probability p($k) of obtaining `$k` from a Pascal distribution with parameters `$p` and `$n`, using the formula given above.

### Pareto

- gsl\_ran\_pareto($r, $a, $b)

  This function returns a random variate from the Pareto distribution of order `$a`. The distribution function is p($x) dx = ($a/$b) / ($x/$b)^{$a+1} dx for `$x` \>= `$b`. `$r` is a gsl\_rng structure

- gsl\_ran\_pareto\_pdf($x, $a, $b)

  This function computes the probability density p(x) at x for a Pareto distribution with exponent a and scale b, using the formula given above.

### Poisson

- gsl\_ran\_poisson($r, $lambda)

  This function returns a random integer from the Poisson distribution with mean `$lambda`. `$r` is a gsl\_rng structure. The probability distribution for Poisson variates is,

  ```
   p(k) = {$lambda**$k \ $k!} exp(-$lambda)
  ```

  for `$k` \>= 0. `$r` is a gsl\_rng structure.

- gsl\_ran\_poisson\_pdf($k, $lambda)

  This function computes the probability p($k) of obtaining `$k` from a Poisson distribution with mean `$lambda`, using the formula given above.

### Rayleigh

- gsl\_ran\_rayleigh($r, $sigma)

  This function returns a random variate from the Rayleigh distribution with scale parameter sigma. The distribution is, p(x) dx = {x \\over \\sigma^2} \\exp(- x^2/(2 \\sigma^2)) dx for x \> 0. `$r` is a gsl\_rng structure

- gsl\_ran\_rayleigh\_pdf($x, $sigma)

  This function computes the probability density p($x) at `$x` for a Rayleigh distribution with scale parameter sigma, using the formula given above.

- gsl\_ran\_rayleigh\_tail($r, $a, $sigma)

  This function returns a random variate from the tail of the Rayleigh distribution with scale parameter `$sigma` and a lower limit of `$a`. The distribution is, p(x) dx = {x \\over \\sigma^2} \\exp ((a^2 - x^2) /(2 \\sigma^2)) dx for x \> a. `$r` is a gsl\_rng structure

- gsl\_ran\_rayleigh\_tail\_pdf($x, $a, $sigma)

  This function computes the probability density p($x) at `$x` for a Rayleigh tail distribution with scale parameter `$sigma` and lower limit `$a`, using the formula given above.

### Student-t

- gsl\_ran\_tdist($r, $nu)

  This function returns a random variate from the t-distribution. The distribution function is, p(x) dx = {\\Gamma((\\nu + 1)/2) \\over \\sqrt{\\pi \\nu} \\Gamma(\\nu/2)} (1 + x^2/\\nu)^{-(\\nu + 1)/2} dx for -\\infty \< x \< +\\infty.

- gsl\_ran\_tdist\_pdf($x, $nu)

  This function computes the probability density p($x) at `$x` for a t-distribution with nu degrees of freedom, using the formula given above.

### Laplace

- gsl\_ran\_laplace($r, $a)

  This function returns a random variate from the Laplace distribution with width `$a`. The distribution is, p(x) dx = {1 \\over 2 a}  \\exp(-\|x/a\|) dx for -\\infty \< x \< \\infty.

- gsl\_ran\_laplace\_pdf($x, $a)

  This function computes the probability density p($x) at `$x` for a Laplace distribution with width `$a`, using the formula given above.

### Levy

- gsl\_ran\_levy($r, $c, $alpha)

  This function returns a random variate from the Levy symmetric stable distribution with scale `$c` and exponent `$alpha`. The symmetric stable probability distribution is defined by a fourier transform, p(x) = {1 \\over 2 \\pi} \\int\_{-\\infty}^{+\\infty} dt \\exp(-it x - \|c t\|^alpha) There is no explicit solution for the form of p(x) and the library does not define a corresponding pdf function. For \\alpha = 1 the distribution reduces to the Cauchy distribution. For \\alpha = 2 it is a Gaussian distribution with \\sigma = \\sqrt{2} c. For \\alpha \< 1 the tails of the distribution become extremely wide. The algorithm only works for 0 \< alpha \<= 2. `$r` is a gsl\_rng structure

- gsl\_ran\_levy\_skew($r, $c, $alpha, $beta)

  This function returns a random variate from the Levy skew stable distribution with scale `$c`, exponent `$alpha` and skewness parameter `$beta`. The skewness parameter must lie in the range \[-1,1\]. The Levy skew stable probability distribution is defined by a fourier transform, p(x) = {1 \\over 2 \\pi} \\int\_{-\\infty}^{+\\infty} dt \\exp(-it x - \|c t\|^alpha (1-i beta sign(t) tan(pi alpha/2))) When \\alpha = 1 the term \\tan(\\pi \\alpha/2) is replaced by -(2/\\pi)\\log\|t\|. There is no explicit solution for the form of p(x) and the library does not define a corresponding pdf function. For `$alpha` = 2 the distribution reduces to a Gaussian distribution with `$sigma` = **sqrt**(2) `$c` and the skewness parameter has no effect. For `$alpha` \< 1 the tails of the distribution become extremely wide. The symmetric distribution corresponds to `$beta` = 0. The algorithm only works for 0 \< `$alpha` \<= 2. The Levy alpha-stable distributions have the property that if N alpha-stable variates are drawn from the distribution p(c, \\alpha, \\beta) then the sum Y = X\_1 + X\_2 + \\dots + X\_N will also be distributed as an alpha-stable variate, p(N^(1/\\alpha) c, \\alpha, \\beta). `$r` is a gsl\_rng structure

### Weibull

- gsl\_ran\_weibull($r, $scale, $exponent)

  This function returns a random variate from the Weibull distribution with `$scale` and `$exponent` (aka scale). The distribution function is

  ```
   p(x) dx = {$exponent \over $scale^$exponent} x^{$exponent-1}
             \exp(-(x/$scale)^$exponent) dx
  ```

  for x \>= 0. `$r` is a gsl\_rng structure

- gsl\_ran\_weibull\_pdf($x, $scale, $exponent)

  This function computes the probability density p($x) at `$x` for a Weibull distribution with `$scale` and `$exponent`, using the formula given above.

### Spherical Vector

- gsl\_ran\_dir\_2d($r)

  This function returns two values. The first is `$x` and the second is `$y` of a random direction vector v = ($x,$y) in two dimensions. The vector is normalized such that \|v\|^2 = `$x`^2 + `$y`^2 = 1. `$r` is a gsl\_rng structure

- gsl\_ran\_dir\_2d\_trig\_method($r)

  This function returns two values. The first is `$x` and the second is `$y` of a random direction vector v = ($x,$y) in two dimensions. The vector is normalized such that \|v\|^2 = `$x`^2 + `$y`^2 = 1. `$r` is a gsl\_rng structure

- gsl\_ran\_dir\_3d($r)

  This function returns three values. The first is `$x`, the second `$y` and the third `$z` of a random direction vector v = ($x,$y,$z) in three dimensions. The vector is normalized such that \|v\|^2 = x^2 + y^2 + z^2 = 1. The method employed is due to Robert E. Knop (CACM 13, 326 (1970)), and explained in Knuth, v2, 3rd ed, p136. It uses the surprising fact that the distribution projected along any axis is actually uniform (this is only true for 3 dimensions).

- gsl\_ran\_dir\_nd (Not yet implemented )

  This function returns a random direction vector v = (x\_1,x\_2,...,x\_n) in n dimensions. The vector is normalized such that

  ```
      |v|^2 = x_1^2 + x_2^2 + ... + x_n^2 = 1.
  ```

  The method uses the fact that a multivariate Gaussian distribution is spherically symmetric. Each component is generated to have a Gaussian distribution, and then the components are normalized. The method is described by Knuth, v2, 3rd ed, p135-136, and attributed to G. W. Brown, Modern Mathematics for the Engineer (1956).

### Shuffling and Sampling

- gsl\_ran\_shuffle

  Please use the `"shuffle"` method in the GSL::RNG module OO interface.

- gsl\_ran\_choose

  Please use the `"choose"` method in the GSL::RNG module OO interface.

- gsl\_ran\_sample

  Please use the `"sample"` method in the GSL::RNG module OO interface.

- gsl\_ran\_discrete\_preproc

  - gsl\_ran\_discrete($r, $g)

  After gsl\_ran\_discrete\_preproc has been called, you use this function to get the discrete random numbers. `$r` is a gsl\_rng structure and `$g` is a gsl\_ran\_discrete structure

- gsl\_ran\_discrete\_pdf($k, $g)

  Returns the probability P\[$k\] of observing the variable `$k`. Since P\[$k\] is not stored as part of the lookup table, it must be recomputed; this computation takes O(K), so if K is large and you care about the original array P\[$k\] used to create the lookup table, then you should just keep this original array P\[$k\] around. `$r` is a gsl\_rng structure and `$g` is a gsl\_ran\_discrete structure

- gsl\_ran\_discrete\_free($g)

  De-allocates the gsl\_ran\_discrete pointed to by g.

```
 You have to add the functions you want to use inside the qw /put_function_here /.
 You can also write use Math::GSL::Randist qw/:all/; to use all available functions of the module.
 Other tags are also available, here is a complete list of all tags for this module :
```

- logarithmic

  - choose

  - exponential

  - gumbel1

  - exppow

  - sample

  - logistic

  - gaussian

  - poisson

  - binomial

  - fdist

  - chisq

  - gamma

  - hypergeometric

  - dirichlet

  - negative

  - flat

  - geometric

  - discrete

  - tdist

  - ugaussian

  - rayleigh

  - dir

  - pascal

  - gumbel2

  - shuffle

  - landau

  - bernoulli

  - weibull

  - multinomial

  - beta

  - lognormal

  - laplace

  - erlang

  - cauchy

  - levy

  - bivariate

  - pareto

  ```
 For example the beta tag contains theses functions : gsl_ran_beta, gsl_ran_beta_pdf.
```

For more information on the functions, we refer you to the GSL official documentation: \<http://www.gnu.org/software/gsl/manual/html\_node/\>

```
 You might also want to write
    use Math::GSL::RNG qw/:all/;
```

since a lot of the functions of Math::GSL::Randist take as argument a structure that is created by Math::GSL::RNG.  Refer to Math::GSL::RNG documentation to see how to create such a structure.

Math::GSL::CDF also contains a structure named gsl\_ran\_discrete\_t. An example is given in the EXAMPLES part on how to use the function related to this structure.

## EXAMPLES

```
    use Math::GSL::Randist qw/:all/;
    print gsl_ran_exponential_pdf(5,2) . "\n";
    use Math::GSL::Randist qw/:all/;
    my $x = Math::GSL::gsl_ran_discrete_t::new;
```

## AUTHORS

Jonathan "Duke" Leto \<jonathan@leto.net\> and Thierry Moisan \<thierry.moisan@gmail.com\>

## COPYRIGHT AND LICENSE

Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
