Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Normally distributed random numbers

`X = randn`

`X = randn(n)`

`X = randn(sz1,...,szN)`

`X = randn(sz)`

`X = randn(___,typename)`

`X = randn(___,'like',p)`

`X = randn`

returns a random scalar drawn
from the standard normal distribution.

`X = randn(`

returns
an `sz1,...,szN`

)`sz1`

-by-...-by-`szN`

array of
random numbers where `sz1,...,szN`

indicate the size
of each dimension. For example, `randn(3,4)`

returns
a 3-by-4 matrix.

`X = randn(___,`

returns
an array of random numbers of data type `typename`

)`typename`

.
The `typename`

input can be either `'single'`

or `'double'`

.
You can use any of the input arguments in the previous syntaxes.

`X = randn(___,'like',`

returns
an array of random numbers like `p`

)`p`

; that is, of
the same object type as `p`

. You can specify either `typename`

or `'like'`

,
but not both.

The `'seed'`

, `'state'`

, and `'twister'`

inputs
to the `randn`

function are not recommended. Use
the `rng`

function instead. For
more information, see Replace Discouraged Syntaxes of rand and randn.

The sequence of numbers produced by

`randn`

is determined by the internal settings of the uniform pseudorandom number generator that underlies`rand`

,`randi`

, and`randn`

. You can control that shared random number generator using`rng`

.

`RandStream`

| `rand`

| `randi`

| `randperm`

| `rng`

| `sprand`

| `sprandn`

- Create Arrays of Random Numbers
- Random Numbers Within a Specific Range
- Random Numbers Within a Sphere
- Random Numbers from Normal Distribution with Specific Mean and Variance
- Creating and Controlling a Random Number Stream
- Class Support for Array-Creation Functions
- Replace Discouraged Syntaxes of rand and randn
- Why Do Random Numbers Repeat After Startup?