randn

Normally distributed random numbers with mean 0 and variance 1.

Category: Mathematics > Random Number Generation

Syntax

X = randn

Returns one random scalar.

X = randn(n)

Returns an n-by-n matrix.

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

Returns an array with the given dimensions.

X = randn(___, classname)

Returns 'double' or 'single' values.

X = randn(s, ___)

Draws from the RandStream object s instead of the global stream.

Description

The samples follow the bell-shaped distribution with mean 0 and standard deviation 1. For a different mean and spread, scale and shift: mu + sigma*randn(...).

Values come from the global stream and can be repeated by calling rng first.

Input arguments

sz1, ..., szN
Dimension sizes. A single value n gives a square matrix; 0 gives an empty array.
classname
'double' (default) or 'single'.
s
A RandStream object.

Output arguments

X
Array of samples from the standard normal distribution.

Example

Repeatable samples, shifted and scaled

rng(1);
x = randn(1, 3);
rng(1);
y = randn(1, 3);
isequal(x, y)
z = 10 + 2*randn(2, 2);
size(z)
class(randn(2, 'single'))
Output
ans = logical
   1
ans = 1×2

     2     2
ans = 'single'

Notes

The values drawn for a given seed do not match the ones MATLAB produces, although the distribution is the same.

See also

rand randi randperm rng