Next Previous Contents

6. gslrand: The GSL Random Number Module

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.

6.1 Random Number Generation Routines

rng_alloc

Synopsis

Allocate an instance of a random number generator

Usage

Rand_Type rng_alloc ([generator])

rng_set

Synopsis

Seed a random number generator

Usage

rng_set ([Rand_Type gen,] ULong_Type seed)

rng_get

Synopsis

rng_get

Usage

x = rng_get ([Rand_Type gen] [, Int_Type num])

rng_get_rng_types

Synopsis

Get a list of all supported generators

Usage

String_Type[] = rng_get_rng_types ()

rng_uniform

Synopsis

Get a uniformly distributed random number

Usage

x = rng_uniform ([Rand_Type gen] [, Int_Type num])

rng_uniform_pos

Synopsis

Generate a uniformly distributed non-zero random number

Usage

x = rng_uniform_pos ([Rand_Type gen] [, Int_Type num])

rng_max

Synopsis

Obtain the maximum value produced by a random number generator

Usage

ULong_Type rng_max (Rand_Type gen)

rng_min

Synopsis

Obtain the minimum value produced by a random number generator

Usage

ULong_Type rng_min (Rand_Type gen)

6.2 Random Number Distributions

ran_bernoulli

Synopsis

Produce Bernoulli distributed random numbers

Usage

x = ran_bernoulli ([Rand_Type gen,] Double_Type p [,Int_Type num]

ran_beta

Synopsis

Produce distributed random numbers

Usage

x = ran_beta ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_binomial

Synopsis

Produce random numbers from the binomial distribution

Usage

x = ran_binomial ([Rand_Type gen,] Double_Type p, Int_Type n [,Int_Type num])

ran_cauchy

Synopsis

Produce random numbers from the Cauchy distribution

Usage

x = ran_cauchy ([Rand_Type gen,] Double_Type mu [,Int_Type num])

ran_chisq

Synopsis

Produce chi-squared distributed random numbers

Usage

x = ran_chisq ([Rand_Type gen,] Double_Type nu [,Int_Type num])

ran_exponential

Synopsis

Produce exponentially distributed random numbers

Usage

x = ran_exponential ([Rand_Type gen,] Double_Type mu [,Int_Type num])

ran_exppow

Synopsis

Produce random numbers from the exponential power distribution

Usage

x = ran_exppow ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])

ran_fdist

Synopsis

Produce F-distributed random numbers

Usage

x = ran_fdist ([Rand_Type gen,] Double_Type nu1, Double_Type nu2 [,Int_Type num])

ran_flat

Synopsis

Produce uniformly distributed random numbers

Usage

x = ran_flat ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_gamma

Synopsis

Produce a random number from the gamma distribution

Usage

x = ran_gamma ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_gaussian

Synopsis

Produce gaussian distributed random numbers

Usage

x = ran_gaussian ([Rand_Type gen,] Double_Type sigma [,Int_Type num])

ran_gaussian_ratio_method

Synopsis

Produce gaussian distributed random numbers

Usage

x = ran_gaussian_ratio_method ([Rand_Type gen,] Double_Type sigma [,Int_Type num])

ran_gaussian_tail

Synopsis

Produce gaussian distributed random numbers from the tail

Usage

x = ran_gaussian_tail ([Rand_Type gen,] Double_Type a, Double_Type sigma [,Int_Type num])

ran_geometric

Synopsis

Produce random integers from the geometric distribution

Usage

x = ran_geometric ([Rand_Type gen,] Double_Type p [,Int_Type num])

ran_gumbel1

Synopsis

Produce random numbers from the type-1 Gumbel distribution

Usage

x = ran_gumbel1 ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_gumbel2

Synopsis

Produce random numbers from the type-2 Gumbel distribution

Usage

x = ran_gumbel2 ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_laplace

Synopsis

Produce random numbers from the Laplace distribution

Usage

x = ran_laplace ([Rand_Type gen,] Double_Type mu [,Int_Type num])

ran_levy

Synopsis

Produce random numbers from the Levy distribution

Usage

x = ran_levy ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])

ran_logarithmic

Synopsis

Produce random numbers from the logarithmic distribution

Usage

x = ran_logarithmic ([Rand_Type gen,] Double_Type p [,Int_Type num])

ran_logistic

Synopsis

Produce random numbers from the logistic distribution

Usage

x = ran_logistic ([Rand_Type gen,] Double_Type mu [,Int_Type num])

ran_lognormal

Synopsis

Produce random numbers from the lognormal distribution

Usage

x = ran_lognormal ([Rand_Type gen,] Double_Type zeta, Double_Type sigma [,Int_Type num])

ran_negative_binomial

Synopsis

Produce random numbers from the negative binomial distribution

Usage

x = ran_negative_binomial ([Rand_Type gen,] Double_Type p, Double_Type n [,Int_Type num])

ran_pareto

Synopsis

Produce random numbers from the Pareto distribution

Usage

x = ran_pareto ([Rand_Type gen,] Double_Type a, Double_Type b [,Int_Type num])

ran_pascal

Synopsis

Produce random numbers from the Pascal distribution

Usage

x = ran_pascal ([Rand_Type gen,] Double_Type p, Int_Type k [,Int_Type num])

ran_poisson

Synopsis

Produce random numbers from the Poisson distribution

Usage

x = ran_poisson ([Rand_Type gen,] Double_Type mu [,Int_Type num])

ran_rayleigh

Synopsis

Produce random numbers from the Rayleigh distribution

Usage

x = ran_rayleigh ([Rand_Type gen,] Double_Type sigma [,Int_Type num])

ran_rayleigh_tail

Synopsis

Produce random numbers from the tail of the Rayleigh distribution

Usage

x = ran_rayleigh_tail ([Rand_Type gen,] Double_Type a, Double_Type sigma [,Int_Type num])

ran_tdist

Synopsis

Produce random numbers from the t-distribution

Usage

x = ran_tdist ([Rand_Type gen,] Double_Type nu [,Int_Type num])

ran_ugaussian

Synopsis

Produce random numbers from the gaussian distribution

Usage

x = ran_ugaussian ([Rand_Type gen] [,Int_Type num])

ran_ugaussian_ratio_method

Synopsis

Produce random numbers from the gaussian distribution

Usage

x = ran_ugaussian_ratio_method ([Rand_Type gen] [,Int_Type num])

ran_ugaussian_tail

Synopsis

Produce random numbers from the tail of the gaussian distribution

Usage

x = ran_ugaussian_tail ([Rand_Type gen,] Double_Type a [,Int_Type num])

ran_weibull

Synopsis

Produce random numbers from the Weibull distribution

Usage

x = ran_weibull ([Rand_Type gen,] Double_Type mu, Double_Type a [,Int_Type num])

6.3 PDF Functions

ran_beta_pdf

Synopsis

S-Lang version of gsl_ran_beta_pdf

Usage

Double_Type[] ran_beta_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_cauchy_pdf

Synopsis

S-Lang version of gsl_ran_cauchy_pdf

Usage

Double_Type[] ran_cauchy_pdf (Double_Type[] x, Double_Type[] a)

ran_chisq_pdf

Synopsis

S-Lang version of gsl_ran_chisq_pdf

Usage

Double_Type[] ran_chisq_pdf (Double_Type[] x, Double_Type[] nu)

ran_erlang_pdf

Synopsis

S-Lang version of gsl_ran_erlang_pdf

Usage

Double_Type[] ran_erlang_pdf (x, a, n)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] n

ran_exponential_pdf

Synopsis

S-Lang version of gsl_ran_exponential_pdf

Usage

Double_Type[] ran_exponential_pdf (Double_Type[] x, Double_Type[] mu)

ran_exppow_pdf

Synopsis

S-Lang version of gsl_ran_exppow_pdf

Usage

Double_Type[] ran_exppow_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_fdist_pdf

Synopsis

S-Lang version of gsl_ran_fdist_pdf

Usage

Double_Type[] ran_fdist_pdf (x, nu1, nu2)

  Double_Type[] x
  Double_Type[] nu1
  Double_Type[] nu2

ran_flat_pdf

Synopsis

S-Lang version of gsl_ran_flat_pdf

Usage

Double_Type[] ran_flat_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_gamma_pdf

Synopsis

S-Lang version of gsl_ran_gamma_pdf

Usage

Double_Type[] ran_gamma_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_gaussian_pdf

Synopsis

S-Lang version of gsl_ran_gaussian_pdf

Usage

Double_Type[] ran_gaussian_pdf (Double_Type[] x, Double_Type[] sigma)

ran_gaussian_tail_pdf

Synopsis

S-Lang version of gsl_ran_gaussian_tail_pdf

Usage

Double_Type[] ran_gaussian_tail_pdf (x, a, sigma)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] sigma

ran_gumbel1_pdf

Synopsis

S-Lang version of gsl_ran_gumbel1_pdf

Usage

Double_Type[] ran_gumbel1_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_gumbel2_pdf

Synopsis

S-Lang version of gsl_ran_gumbel2_pdf

Usage

Double_Type[] ran_gumbel2_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_landau_pdf

Synopsis

S-Lang version of gsl_ran_landau_pdf

Usage

Double_Type[] ran_landau_pdf (Double_Type[] x)

ran_laplace_pdf

Synopsis

S-Lang version of gsl_ran_laplace_pdf

Usage

Double_Type[] ran_laplace_pdf (Double_Type[] x, Double_Type[] a)

ran_logistic_pdf

Synopsis

S-Lang version of gsl_ran_logistic_pdf

Usage

Double_Type[] ran_logistic_pdf (Double_Type[] x, Double_Type[] a)

ran_lognormal_pdf

Synopsis

S-Lang version of gsl_ran_lognormal_pdf

Usage

Double_Type[] ran_lognormal_pdf (x, zeta, sigma)

  Double_Type[] x
  Double_Type[] zeta
  Double_Type[] sigma

ran_pareto_pdf

Synopsis

S-Lang version of gsl_ran_pareto_pdf

Usage

Double_Type[] ran_pareto_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b

ran_rayleigh_pdf

Synopsis

S-Lang version of gsl_ran_rayleigh_pdf

Usage

Double_Type[] ran_rayleigh_pdf (Double_Type[] x, Double_Type[] sigma)

ran_rayleigh_tail_pdf

Synopsis

S-Lang version of gsl_ran_rayleigh_tail_pdf

Usage

Double_Type[] ran_rayleigh_tail_pdf (x, a, sigma)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] sigma

ran_tdist_pdf

Synopsis

S-Lang version of gsl_ran_tdist_pdf

Usage

Double_Type[] ran_tdist_pdf (Double_Type[] x, Double_Type[] nu)

ran_ugaussian_pdf

Synopsis

S-Lang version of gsl_ran_ugaussian_pdf

Usage

Double_Type[] ran_ugaussian_pdf (Double_Type[] x)

ran_ugaussian_tail_pdf

Synopsis

S-Lang version of gsl_ran_ugaussian_tail_pdf

Usage

Double_Type[] ran_ugaussian_tail_pdf (Double_Type[] x, Double_Type[] a)

ran_weibull_pdf

Synopsis

S-Lang version of gsl_ran_weibull_pdf

Usage

Double_Type[] ran_weibull_pdf (x, a, b)

  Double_Type[] x
  Double_Type[] a
  Double_Type[] b


Next Previous Contents