Previous: , Up: Statistics   [Contents][Index]


26.7 Random Number Generation

Octave can generate random numbers from a large number of distributions. The random number generators are based on the random number generators described in Special Utility Matrices.

The following table summarizes the available random number generators (in alphabetical order).

DistributionFunction
Beta Distributionbetarnd
Binomial Distributionbinornd
Cauchy Distributioncauchy_rnd
Chi-Square Distributionchi2rnd
Univariate Discrete Distributiondiscrete_rnd
Empirical Distributionempirical_rnd
Exponential Distributionexprnd
F Distributionfrnd
Gamma Distributiongamrnd
Geometric Distributiongeornd
Hypergeometric Distributionhygernd
Laplace Distributionlaplace_rnd
Logistic Distributionlogistic_rnd
Log-Normal Distributionlognrnd
Pascal Distributionnbinrnd
Univariate Normal Distributionnormrnd
Poisson Distributionpoissrnd
Standard Normal Distributionstdnormal_rnd
t (Student) Distributiontrnd
Univariate Discrete Distributionunidrnd
Uniform Distributionunifrnd
Weibull Distributionwblrnd
Wiener Processwienrnd
: betarnd (a, b)
: betarnd (a, b, r)
: betarnd (a, b, r, c, …)
: betarnd (a, b, [sz])

Return a matrix of random samples from the Beta distribution with parameters a and b.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of a and b.

: binornd (n, p)
: binornd (n, p, r)
: binornd (n, p, r, c, …)
: binornd (n, p, [sz])

Return a matrix of random samples from the binomial distribution with parameters n and p, where n is the number of trials and p is the probability of success.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of n and p.

: cauchy_rnd (location, scale)
: cauchy_rnd (location, scale, r)
: cauchy_rnd (location, scale, r, c, …)
: cauchy_rnd (location, scale, [sz])

Return a matrix of random samples from the Cauchy distribution with parameters location and scale.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of location and scale.

: chi2rnd (n)
: chi2rnd (n, r)
: chi2rnd (n, r, c, …)
: chi2rnd (n, [sz])

Return a matrix of random samples from the chi-square distribution with n degrees of freedom.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of n.

: discrete_rnd (v, p)
: discrete_rnd (v, p, r)
: discrete_rnd (v, p, r, c, …)
: discrete_rnd (v, p, [sz])

Return a matrix of random samples from the univariate distribution which assumes the values in v with probabilities p.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of v and p.

: empirical_rnd (data)
: empirical_rnd (data, r)
: empirical_rnd (data, r, c, …)
: empirical_rnd (data, [sz])

Return a matrix of random samples from the empirical distribution obtained from the univariate sample data.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is a random ordering of the sample data.

: exprnd (lambda)
: exprnd (lambda, r)
: exprnd (lambda, r, c, …)
: exprnd (lambda, [sz])

Return a matrix of random samples from the exponential distribution with mean lambda.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of lambda.

: frnd (m, n)
: frnd (m, n, r)
: frnd (m, n, r, c, …)
: frnd (m, n, [sz])

Return a matrix of random samples from the F distribution with m and n degrees of freedom.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of m and n.

: gamrnd (a, b)
: gamrnd (a, b, r)
: gamrnd (a, b, r, c, …)
: gamrnd (a, b, [sz])

Return a matrix of random samples from the Gamma distribution with shape parameter a and scale b.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of a and b.

: geornd (p)
: geornd (p, r)
: geornd (p, r, c, …)
: geornd (p, [sz])

Return a matrix of random samples from the geometric distribution with parameter p.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of p.

The geometric distribution models the number of failures (x-1) of a Bernoulli trial with probability p before the first success (x).

: hygernd (t, m, n)
: hygernd (t, m, n, r)
: hygernd (t, m, n, r, c, …)
: hygernd (t, m, n, [sz])

Return a matrix of random samples from the hypergeometric distribution with parameters t, m, and n.

The parameters t, m, and n must be positive integers with m and n not greater than t.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of t, m, and n.

: laplace_rnd (r)
: laplace_rnd (r, c, …)
: laplace_rnd ([sz])

Return a matrix of random samples from the Laplace distribution.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

: logistic_rnd (r)
: logistic_rnd (r, c, …)
: logistic_rnd ([sz])

Return a matrix of random samples from the logistic distribution.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

: lognrnd (mu, sigma)
: lognrnd (mu, sigma, r)
: lognrnd (mu, sigma, r, c, …)
: lognrnd (mu, sigma, [sz])

Return a matrix of random samples from the lognormal distribution with parameters mu and sigma.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of mu and sigma.

: nbinrnd (n, p)
: nbinrnd (n, p, r)
: nbinrnd (n, p, r, c, …)
: nbinrnd (n, p, [sz])

Return a matrix of random samples from the negative binomial distribution with parameters n and p.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of n and p.

: normrnd (mu, sigma)
: normrnd (mu, sigma, r)
: normrnd (mu, sigma, r, c, …)
: normrnd (mu, sigma, [sz])

Return a matrix of random samples from the normal distribution with parameters mean mu and standard deviation sigma.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of mu and sigma.

: poissrnd (lambda)
: poissrnd (lambda, r)
: poissrnd (lambda, r, c, …)
: poissrnd (lambda, [sz])

Return a matrix of random samples from the Poisson distribution with parameter lambda.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of lambda.

: stdnormal_rnd (r)
: stdnormal_rnd (r, c, …)
: stdnormal_rnd ([sz])

Return a matrix of random samples from the standard normal distribution (mean = 0, standard deviation = 1).

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

: trnd (n)
: trnd (n, r)
: trnd (n, r, c, …)
: trnd (n, [sz])

Return a matrix of random samples from the t (Student) distribution with n degrees of freedom.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of n.

: unidrnd (n)
: unidrnd (n, r)
: unidrnd (n, r, c, …)
: unidrnd (n, [sz])

Return a matrix of random samples from the discrete uniform distribution which assumes the integer values 1–n with equal probability.

n may be a scalar or a multi-dimensional array.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of n.

: unifrnd (a, b)
: unifrnd (a, b, r)
: unifrnd (a, b, r, c, …)
: unifrnd (a, b, [sz])

Return a matrix of random samples from the uniform distribution on [a, b].

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of a and b.

: wblrnd (scale, shape)
: wblrnd (scale, shape, r)
: wblrnd (scale, shape, r, c, …)
: wblrnd (scale, shape, [sz])

Return a matrix of random samples from the Weibull distribution with parameters scale and shape.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of scale and shape.

: wienrnd (t, d, n)

Return a simulated realization of the d-dimensional Wiener Process on the interval [0, t].

If d is omitted, d = 1 is used. The first column of the return matrix contains time, the remaining columns contain the Wiener process.

The optional parameter n defines the number of summands used for simulating the process over an interval of length 1. If n is omitted, n = 1000 is used.


Previous: , Up: Statistics   [Contents][Index]