MATLAB Function Reference | Search Help Desk |

randn | Examples See Also |

Normally distributed random numbers and arrays

Y = randn(n) Y = randn(m,n) Y = randn([m n]) Y = randn(m,n,p,...) Y = randn([m n p...]) Y = randn(size(A)) randn s = randn('state')The

`randn`

function generates arrays of random numbers whose elements are normally distributed with mean 0 and variance 1.
```
Y = randn(n)
```

returns an `n`

-by-`n`

matrix of random entries. An error message appears if `n`

is not a scalar.
```
Y = randn(m,n) or Y = randn([m n])
```

returns an `m`

-by-`n`

matrix of random entries.
```
Y = randn(m,n,p,...) or Y = randn([m n p...])
```

generates random arrays.
```
Y = randn(size(A))
```

returns an array of random entries that is the same size as `A`

.
`randn`

,

by itself, returns a scalar whose value changes each time it's referenced.
```
s = randn('state')
```

returns a 2-element vector containing the current state of the normal generator. To change the state of the generator:`randn('seed',0)`

and` randn('seed',j)`

use the MATLAB 4 generator. `randn('seed')`

returns the current seed of the MATLAB 4 normal generator. `randn('state',j)`

and `randn('state',s)`

use the MATLAB 5 generator.
`R`

`=`

`randn(3,4)`

may produce
R = 1.1650 0.3516 0.0591 0.8717 0.6268 -0.6965 1.7971 -1.4462 0.0751 1.6961 0.2641 -0.7012For a histogram of the

`randn`

distribution, see `hist`

.
`rand`

` `

Uniformly distributed random numbers and arrays
`randperm`

` `

Random permutation

`sprand`

` `

Sparse uniformly distributed random matrix

`sprandn`

` `

Sparse normally distributed random matrix