# geornd

Geometric random numbers

## Syntax

```r = geornd(p) r = geornd(p,m,n,...) r = geornd(p,[m,n,...]) ```

## Description

`r = geornd(p)` generates random numbers from a geometric distribution with probability parameter `p`. `p` can be a vector, a matrix, or a multidimensional array. The size of `r` is equal to the size of `p`. The parameters in `p` must lie in the interval `[0,1]`.

`r = geornd(p,m,n,...)` or `r = geornd(p,[m,n,...])` generates a multidimensional `m`-by-`n`-by-`...` array containing random numbers from the geometric distribution with probability parameter `p`. `p` can be a scalar or an array of the same size as `r`.

The geometric distribution is useful to model the number of failures before one success in a series of independent trials, where each trial results in either success or failure, and the probability of success in any individual trial is the constant `p`.

## Examples

collapse all

Generate a single random number from a geometric distribution with probability parameter p equal to 0.01.

```rng default % For reproducibility p = 0.01; r1 = geornd(0.01)```
```r1 = 20 ```

The returned random number represents a single experiment in which 20 failures were observed before a success, where each independent trial has a probability of success p equal to 0.01.

Generate a 1-by-5 array of random numbers from a geometric distribution with probability parameter p equal to 0.01.

`r2 = geornd(p,1,5)`
```r2 = 1×5 9 205 9 45 231 ```

Each random number in the returned array represents the result of an experiment to determine the number of failures observed before a success, where each independent trial has a probability of success p equal to 0.01.

Generate a 1-by-3 array containing one random number from each of the three geometric distributions corresponding to the parameters in the 1-by-3 array of probabilities p.

```p = [0.01 0.1 0.5]; r3 = geornd(p,[1 3])```
```r3 = 1×3 127 5 0 ```

Each element of the returned 1-by-3 array `r3` contains one random number generated from the geometric distribution described by the corresponding parameter in `P`. For example, the first element in `r3` represents an experiment in which 127 failures were observed before a success, where each independent trial has a probability of success p equal to 0.01. The second element in `r3` represents an experiment in which 5 failures were observed before a success, where each independent trial has a probability of success p equal to 0.1. The third element in `r3` represents an experiment in which zero failures were observed before a success - in other words, the first attempt was a success - where each independent trial has a probability of success p equal to 0.5.

## Version History

Introduced before R2006a