GSL provides more than 60 types of random number generators and about
40 random number distributions. The gslrand
module
provides access to all of the GSL random number generators and to
nearly all of its random number distributions.
Using the gslrand
module is rather straightforward. First,
import the module into the interpreter as described above via a
statement such as
require ("gslrand");
The next step is to allocate a random number generator via the
rng_alloc
function. As stated above, there are more than 60
generators to choose from. To allocate an instance of the default
generator ("mt19937"
), use
r = rng_alloc ();
Or to allocate an instance of some other generator, e.g., the
lagged-fibonacci generator "gfsr4"
, use
r = rng_alloc ("gfsr4");
Once the generator has been allocated, it may be used to construct
random number sequences from a specific random distribution. For
example,
x = ran_flat (r, 0, 1);
may be used to obtain a random number uniformly distributed between 0
and 1. In a similar vein,
x = ran_gaussian (r, 2.0);
will produce a gaussian distributed random number with a sigma of 2.0.
For many applications, it is desirable to be able to produce arrays of random numbers. This may be accomplished by passing an addition argument to the random number distribution function that specifies how many random numbers to produce. For example,
a = ran_gaussian (r, 2.0, 10000);
will create an array of 10000 gaussian distributed random numbers
with a sigma of 2.0.
If the random generator is omitted from the call to the random number distribution routines, then a default generator will be used. For example,
x = ran_gaussian (2.0);
will generate a gaussian distributed random number with a sigma of
2.0 using the default generator.
Allocate an instance of a random number generator
Rand_Type rng_alloc ([generator])
Seed a random number generator
rng_set ([Rand_Type gen,] ULong_Type seed)
rng_get
x = rng_get ([Rand_Type gen] [, Int_Type num])
Get a list of all supported generators
String_Type[] = rng_get_rng_types ()
Get a uniformly distributed random number
x = rng_uniform ([Rand_Type gen] [, Int_Type num])
Generate a uniformly distributed non-zero random number
x = rng_uniform_pos ([Rand_Type gen] [, Int_Type num])
Obtain the maximum value produced by a random number generator
ULong_Type rng_max (Rand_Type gen)
Obtain the minimum value produced by a random number generator
ULong_Type rng_min (Rand_Type gen)
Produce Bernoulli distributed random numbers
x = ran_bernoulli ([Rand_Type gen,] Double_Type p [,Int_Type num]
Produce distributed random numbers
x = ran_beta ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce random numbers from the binomial distribution
x = ran_binomial ([Rand_Type gen,] Double_Type p, Int_Type n [,Int_Type num])
Produce random numbers from the Cauchy distribution
x = ran_cauchy ([Rand_Type gen,] Double_Type mu [,Int_Type num])
Produce chi-squared distributed random numbers
x = ran_chisq ([Rand_Type gen,] Double_Type nu [,Int_Type num])
Produce exponentially distributed random numbers
x = ran_exponential ([Rand_Type gen,] Double_Type mu [,Int_Type num])
Produce random numbers from the exponential power distribution
x = ran_exppow ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])
Produce F-distributed random numbers
x = ran_fdist ([Rand_Type gen,] Double_Type nu1, Double_Type nu2 [,Int_Type num])
Produce uniformly distributed random numbers
x = ran_flat ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce a random number from the gamma distribution
x = ran_gamma ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce gaussian distributed random numbers
x = ran_gaussian ([Rand_Type gen,] Double_Type sigma [,Int_Type num])
Produce gaussian distributed random numbers
x = ran_gaussian_ratio_method ([Rand_Type gen,] Double_Type sigma [,Int_Type num])
Produce gaussian distributed random numbers from the tail
x = ran_gaussian_tail ([Rand_Type gen,] Double_Type a, Double_Type sigma [,Int_Type num])
Produce random integers from the geometric distribution
x = ran_geometric ([Rand_Type gen,] Double_Type p [,Int_Type num])
Produce random numbers from the type-1 Gumbel distribution
x = ran_gumbel1 ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce random numbers from the type-2 Gumbel distribution
x = ran_gumbel2 ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce random numbers from the Laplace distribution
x = ran_laplace ([Rand_Type gen,] Double_Type mu [,Int_Type num])
Produce random numbers from the Levy distribution
x = ran_levy ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])
Produce random numbers from the logarithmic distribution
x = ran_logarithmic ([Rand_Type gen,] Double_Type p [,Int_Type num])
Produce random numbers from the logistic distribution
x = ran_logistic ([Rand_Type gen,] Double_Type mu [,Int_Type num])
Produce random numbers from the lognormal distribution
x = ran_lognormal ([Rand_Type gen,] Double_Type zeta, Double_Type sigma [,Int_Type num])
Produce random numbers from the negative binomial distribution
x = ran_negative_binomial ([Rand_Type gen,] Double_Type p, Double_Type n [,Int_Type num])
Produce random numbers from the Pareto distribution
x = ran_pareto ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])
Produce random numbers from the Pascal distribution
x = ran_pascal ([Rand_Type gen,] Double_Type p, Int_Type k [,Int_Type num])
Produce random numbers from the Poisson distribution
x = ran_poisson ([Rand_Type gen,] Double_Type mu [,Int_Type num])
Produce random numbers from the Rayleigh distribution
x = ran_rayleigh ([Rand_Type gen,] Double_Type sigma [,Int_Type num])
Produce random numbers from the tail of the Rayleigh distribution
x = ran_rayleigh_tail ([Rand_Type gen,] Double_Type a, Double_Type sigma [,Int_Type num])
Produce random numbers from the t-distribution
x = ran_tdist ([Rand_Type gen,] Double_Type nu [,Int_Type num])
Produce random numbers from the gaussian distribution
x = ran_ugaussian ([Rand_Type gen] [,Int_Type num])
Produce random numbers from the gaussian distribution
x = ran_ugaussian_ratio_method ([Rand_Type gen] [,Int_Type num])
Produce random numbers from the tail of the gaussian distribution
x = ran_ugaussian_tail ([Rand_Type gen,] Double_Type a [,Int_Type num])
Produce random numbers from the Weibull distribution
x = ran_weibull ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])
S-Lang version of gsl_ran_beta_pdf
Double_Type[] ran_beta_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_cauchy_pdf
Double_Type[] ran_cauchy_pdf (Double_Type[] x, Double_Type[] a)
S-Lang version of gsl_ran_chisq_pdf
Double_Type[] ran_chisq_pdf (Double_Type[] x, Double_Type[] nu)
S-Lang version of gsl_ran_erlang_pdf
Double_Type[] ran_erlang_pdf (x, a, n)
Double_Type[] x
Double_Type[] a
Double_Type[] n
S-Lang version of gsl_ran_exponential_pdf
Double_Type[] ran_exponential_pdf (Double_Type[] x, Double_Type[] mu)
S-Lang version of gsl_ran_exppow_pdf
Double_Type[] ran_exppow_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_fdist_pdf
Double_Type[] ran_fdist_pdf (x, nu1, nu2)
Double_Type[] x
Double_Type[] nu1
Double_Type[] nu2
S-Lang version of gsl_ran_flat_pdf
Double_Type[] ran_flat_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_gamma_pdf
Double_Type[] ran_gamma_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_gaussian_pdf
Double_Type[] ran_gaussian_pdf (Double_Type[] x, Double_Type[] sigma)
S-Lang version of gsl_ran_gaussian_tail_pdf
Double_Type[] ran_gaussian_tail_pdf (x, a, sigma)
Double_Type[] x
Double_Type[] a
Double_Type[] sigma
S-Lang version of gsl_ran_gumbel1_pdf
Double_Type[] ran_gumbel1_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_gumbel2_pdf
Double_Type[] ran_gumbel2_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_landau_pdf
Double_Type[] ran_landau_pdf (Double_Type[] x)
S-Lang version of gsl_ran_laplace_pdf
Double_Type[] ran_laplace_pdf (Double_Type[] x, Double_Type[] a)
S-Lang version of gsl_ran_logistic_pdf
Double_Type[] ran_logistic_pdf (Double_Type[] x, Double_Type[] a)
S-Lang version of gsl_ran_lognormal_pdf
Double_Type[] ran_lognormal_pdf (x, zeta, sigma)
Double_Type[] x
Double_Type[] zeta
Double_Type[] sigma
S-Lang version of gsl_ran_pareto_pdf
Double_Type[] ran_pareto_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b
S-Lang version of gsl_ran_rayleigh_pdf
Double_Type[] ran_rayleigh_pdf (Double_Type[] x, Double_Type[] sigma)
S-Lang version of gsl_ran_rayleigh_tail_pdf
Double_Type[] ran_rayleigh_tail_pdf (x, a, sigma)
Double_Type[] x
Double_Type[] a
Double_Type[] sigma
S-Lang version of gsl_ran_tdist_pdf
Double_Type[] ran_tdist_pdf (Double_Type[] x, Double_Type[] nu)
S-Lang version of gsl_ran_ugaussian_pdf
Double_Type[] ran_ugaussian_pdf (Double_Type[] x)
S-Lang version of gsl_ran_ugaussian_tail_pdf
Double_Type[] ran_ugaussian_tail_pdf (Double_Type[] x, Double_Type[] a)
S-Lang version of gsl_ran_weibull_pdf
Double_Type[] ran_weibull_pdf (x, a, b)
Double_Type[] x
Double_Type[] a
Double_Type[] b