# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# random

Class: prob.TruncatableDistribution
Package: prob

Generate random numbers from probability distribution object

## Syntax

```r = random(pd) r = random(pd,sz1,...,szN) r = random(pd,[sz1,...,szN]) ```

## Description

`r = random(pd)` generates a random number `r` from the probability distribution `pd`.

`r = random(pd,sz1,...,szN)` generates a sz1-by-...-by-szN array of random numbers from the probability distribution `pd`.

`r = random(pd,[sz1,...,szN])` generates a sz1-by-...-by-szN array of random numbers from the probability distribution `pd`.

## Input Arguments

expand all

Probability distribution, specified as a probability distribution object. Create a probability distribution object with specified parameter values using `makedist`. Alternatively, for fittable distributions, create a probability distribution object by fitting it to data using `fitdist` or the Distribution Fitting app.

Size of each dimension, specified as two or more integer values, or a vector of such values. For example, specifying `5,3,2` or `[5,3,2]` generates a 5-by-3-by-2 array of random numbers from the probability distribution `pd`.

Data Types: `single` | `double`

## Output Arguments

expand all

Random number generated from the probability distribution, returned as a scalar value or an array of scalar values with the dimensions specified by `sz1,...,szN`.

## Examples

expand all

Create a standard normal probability distribution object.

```pd = makedist('Normal') ```
```pd = NormalDistribution Normal distribution mu = 0 sigma = 1 ```

Generate one random number from the distribution.

```r = random(pd) ```
```r = 0.5377 ```

Create a Weibull probability distribution object using the default parameter values.

```pd = makedist('Weibull') ```
```pd = WeibullDistribution Weibull distribution A = 1 B = 1 ```

Generate random numbers from distribution and visualize with a histogram.

```rng default % For reproducibility r = random(pd,10000,1); histogram(r,100) ```

Create a standard normal probability distribution object.

```pd = makedist('Normal') ```
```pd = NormalDistribution Normal distribution mu = 0 sigma = 1 ```

Generate a 2-by-3-by-2 array of random numbers from the distribution.

```r = random(pd,[2,3,2]) ```
```r(:,:,1) = 0.5377 -2.2588 0.3188 1.8339 0.8622 -1.3077 r(:,:,2) = -0.4336 3.5784 -1.3499 0.3426 2.7694 3.0349 ```