# GSL: The GNU Scientific Library

GSL is a library that provides many useful scientific functions, including random number generation, random number distributions, statistics, fast fourier transform, and root finding. The latest version is gsl-0.4.1 released January 1999. The source code is installed in /usr/dirt/src/gsl-0.4.1/, the library files (compiled on FreeBSD 2.2.8) are in /usr/dirt/lib/, and the header files are in /usr/dirt/include/.

On this web page, I've included links to the GSL main web page and the GSL manual, a list of available random number distributions, an example on how to use GSL in your own program, and some notes on how to re-build the library.

## Available Distributions

Continuous
 gaussian (sigma) bivariate gaussian (sigma_x, sigma_y, rho, x, y) exponential (mu) laplace (mu) exponential power (mu, a) cauchy (mu) rayleigh (sigma) rayleigh tail (a, sigma) symmetric levy (mu, a) gamma (a, b) flat/uniform (a, b) lognormal (zeta, sigma) chi-squared (mu) F-distribution (nu1, nu2) t-distribution (nu) beta (a, b) logistic (mu) pareto (a, b) spherical_2d (x, y) spherical_3d (x, y, z) weibull (mu, a) gumbel (a, b)

Discrete

 poisson (mu) bernoulli (p) binomial (p, n) negative binomial (p, n) geometric (p) hypergeometric (n1, n2, t) logarithmic (p)

## Example (Random Number Distribution)

```#include "gsl_randist.h"

int main (void)
{
double packet_size;
long seed;
gsl_rng *rng;  // random number generator

rng = gsl_rng_alloc (gsl_rng_rand48);     // pick random number generator
seed = time (NULL) * getpid();
gsl_rng_set (rng, seed);                  // set seed
packet_size = gsl_ran_exponential (1500); // get a random number from
// the exponential distribution
gsl_rng_free (rng);                       // dealloc the rng
}

% gcc -L /usr/dirt/lib -lgslrandist -lgslrng -lgslerr -lgslspecfunc [..]
```
Note -- If you want to use GSL with C++, include the gsl header file like this:
```extern "C" {
#include "gsl_randist.h"
}
```

## Notes on Re-building GSL

• Basic Procedure:
```  [.../gsl/]% ./configure
[.../gsl/your favorite library/]% cp gsl_*.h /usr/dirt/include
[.../gsl/your favorite library/]% cp lib*.a /usr/dirt/lib```
• It may (or may not) have been fixed in future releases, but in the randist directory, cfree() is used in the file gsl_randist.c. FreeBSD does not support cfree() by default, but the library works if you replace the call to cfree() with free(). There's only one instance of it in the entire library.

• If you want to build only libraries needed for random number distributions, you'll have to build the following (in this order):
• err
• sys
• utils
• specfunc
• rng
• randist

Other DiRT documents
Author: Michele Clark