[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |

## 25.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).

| |

Beta Distribution | |

Binomial Distribution | |

Cauchy Distribution | |

Chi-Square Distribution | |

Univariate Discrete Distribution | |

Empirical Distribution | |

Exponential Distribution | |

F Distribution | |

Gamma Distribution | |

Geometric Distribution | |

Hypergeometric Distribution | |

Laplace Distribution | |

Logistic Distribution | |

Log-Normal Distribution | |

Pascal Distribution | |

Univariate Normal Distribution | |

Poisson Distribution | |

t (Student) Distribution | |

Univariate Discrete Distribution | |

Uniform Distribution | |

Weibull Distribution | |

Wiener Process | |

__Function File:__**betarnd***(*`a`,`b`,`r`,`c`)__Function File:__**betarnd***(*`a`,`b`,`sz`)Return an

`r`by`c`or`size (`

matrix of random samples from the Beta distribution with parameters`sz`)`a`and`b`. Both`a`and`b`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`a`and`b`.

__Function File:__**binornd***(*`n`,`p`,`r`,`c`)__Function File:__**binornd***(*`n`,`p`,`sz`)Return an

`r`by`c`or a`size (`

matrix of random samples from the binomial distribution with parameters`sz`)`n`and`p`. Both`n`and`p`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`n`and`p`.

__Function File:__**cauchy_rnd***(*`lambda`,`sigma`,`r`,`c`)__Function File:__**cauchy_rnd***(*`lambda`,`sigma`,`sz`)Return an

`r`by`c`or a`size (`

matrix of random samples from the Cauchy distribution with parameters`sz`)`lambda`and`sigma`which must both be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`lambda`and`sigma`.

__Function File:__**chi2rnd***(*`n`,`r`,`c`)__Function File:__**chi2rnd***(*`n`,`sz`)Return an

`r`by`c`or a`size (`

matrix of random samples from the chisquare distribution with`sz`)`n`degrees of freedom.`n`must be a scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the size of`n`.

__Function File:__**discrete_rnd***(*`n`,`v`,`p`)__Function File:__**discrete_rnd***(*`v`,`p`,`r`,`c`)__Function File:__**discrete_rnd***(*`v`,`p`,`sz`)Generate a row vector containing a random sample of size

`n`from the univariate distribution which assumes the values in`v`with probabilities`p`.`n`must be a scalar.If

`r`and`c`are given create a matrix with`r`rows and`c`columns. Or if`sz`is a vector, create a matrix of size`sz`.

__Function File:__**empirical_rnd***(*`n`,`data`)__Function File:__**empirical_rnd***(*`data`,`r`,`c`)__Function File:__**empirical_rnd***(*`data`,`sz`)Generate a bootstrap sample of size

`n`from the empirical distribution obtained from the univariate sample`data`.If

`r`and`c`are given create a matrix with`r`rows and`c`columns. Or if`sz`is a vector, create a matrix of size`sz`.

__Function File:__**exprnd***(*`lambda`,`r`,`c`)__Function File:__**exprnd***(*`lambda`,`sz`)Return an

`r`by`c`matrix of random samples from the exponential distribution with mean`lambda`, which must be a scalar or of size`r`by`c`. Or if`sz`is a vector, create a matrix of size`sz`.If

`r`and`c`are omitted, the size of the result matrix is the size of`lambda`.

__Function File:__**frnd***(*`m`,`n`,`r`,`c`)__Function File:__**frnd***(*`m`,`n`,`sz`)Return an

`r`by`c`matrix of random samples from the F distribution with`m`and`n`degrees of freedom. Both`m`and`n`must be scalar or of size`r`by`c`. If`sz`is a vector the random samples are in a matrix of size`sz`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`m`and`n`.

__Function File:__**gamrnd***(*`a`,`b`,`r`,`c`)__Function File:__**gamrnd***(*`a`,`b`,`sz`)Return an

`r`by`c`or a`size (`

matrix of random samples from the Gamma distribution with parameters`sz`)`a`and`b`. Both`a`and`b`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`a`and`b`.

__Function File:__**geornd***(*`p`,`r`,`c`)__Function File:__**geornd***(*`p`,`sz`)Return an

`r`by`c`matrix of random samples from the geometric distribution with parameter`p`, which must be a scalar or of size`r`by`c`.If

`r`and`c`are given create a matrix with`r`rows and`c`columns. Or if`sz`is a vector, create a matrix of size`sz`.

__Function File:__**hygernd***(*`t`,`m`,`n`,`r`,`c`)__Function File:__**hygernd***(*`t`,`m`,`n`,`sz`)__Function File:__**hygernd***(*`t`,`m`,`n`)Return an

`r`by`c`matrix of random samples from the hypergeometric distribution with parameters`t`,`m`, and`n`.The parameters

`t`,`m`, and`n`must positive integers with`m`and`n`not greater than`t`.The parameter

`sz`must be scalar or a vector of matrix dimensions. If`sz`is scalar, then a`sz`by`sz`matrix of random samples is generated.

__Function File:__**laplace_rnd***(*`r`,`c`)__Function File:__**laplace_rnd***(*`sz`);Return an

`r`by`c`matrix of random numbers from the Laplace distribution. Or if`sz`is a vector, create a matrix of`sz`.

__Function File:__**logistic_rnd***(*`r`,`c`)__Function File:__**logistic_rnd***(*`sz`)Return an

`r`by`c`matrix of random numbers from the logistic distribution. Or if`sz`is a vector, create a matrix of`sz`.

__Function File:__**lognrnd***(*`mu`,`sigma`,`r`,`c`)__Function File:__**lognrnd***(*`mu`,`sigma`,`sz`)Return an

`r`by`c`matrix of random samples from the lognormal distribution with parameters`mu`and`sigma`. Both`mu`and`sigma`must be scalar or of size`r`by`c`. Or if`sz`is a vector, create a matrix of size`sz`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`mu`and`sigma`.

__Function File:__**nbinrnd***(*`n`,`p`,`r`,`c`)__Function File:__**nbinrnd***(*`n`,`p`,`sz`)Return an

`r`by`c`matrix of random samples from the Pascal (negative binomial) distribution with parameters`n`and`p`. Both`n`and`p`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`n`and`p`. Or if`sz`is a vector, create a matrix of size`sz`.

__Function File:__**normrnd***(*`m`,`s`,`r`,`c`)__Function File:__**normrnd***(*`m`,`s`,`sz`)Return an

`r`by`c`or`size (`

matrix of random samples from the normal distribution with parameters mean`sz`)`m`and standard deviation`s`. Both`m`and`s`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`m`and`s`.

__Function File:__**poissrnd***(*`lambda`,`r`,`c`)Return an

`r`by`c`matrix of random samples from the Poisson distribution with parameter`lambda`, which must be a scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the size of`lambda`.

__Function File:__**trnd***(*`n`,`r`,`c`)__Function File:__**trnd***(*`n`,`sz`)Return an

`r`by`c`matrix of random samples from the t (Student) distribution with`n`degrees of freedom.`n`must be a scalar or of size`r`by`c`. Or if`sz`is a vector create a matrix of size`sz`.If

`r`and`c`are omitted, the size of the result matrix is the size of`n`.

__Function File:__**unidrnd***(*`mx`);__Function File:__**unidrnd***(*`mx`,`v`);__Function File:__**unidrnd***(*`mx`,`m`,`n`, …);Return random values from discrete uniform distribution, with maximum value(s) given by the integer

`mx`, which may be a scalar or multidimensional array.If

`mx`is a scalar, the size of the result is specified by the vector`v`, or by the optional arguments`m`,`n`, …. Otherwise, the size of the result is the same as the size of`mx`.

__Function File:__**unifrnd***(*`a`,`b`,`r`,`c`)__Function File:__**unifrnd***(*`a`,`b`,`sz`)Return an

`r`by`c`or a`size (`

matrix of random samples from the uniform distribution on [`sz`)`a`,`b`]. Both`a`and`b`must be scalar or of size`r`by`c`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`a`and`b`.

__Function File:__**wblrnd***(*`scale`,`shape`,`r`,`c`)__Function File:__**wblrnd***(*`scale`,`shape`,`sz`)Return an

`r`by`c`matrix of random samples from the Weibull distribution with parameters`scale`and`shape`which must be scalar or of size`r`by`c`. Or if`sz`is a vector return a matrix of size`sz`.If

`r`and`c`are omitted, the size of the result matrix is the common size of`alpha`and`sigma`.

__Function File:__**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`gives the number of summands used for simulating the process over an interval of length 1. If`n`is omitted,`n`= 1000 is used.

[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |