randn

Purpose

Normally distributed random numbers and matrices.

Synopsis

Y = randn(n)
Y = randn(m,n)
Y = randn(size(A))
randn('seed')
randn('seed',n)
randn

Description

randn generates random numbers and matrices whose elements are normally distributed with mean 0 and variance 1.

randn(n) is an n-by-n matrix with random entries.

randn(m,n) is an m-by-n matrix with random entries.

randn(size(A)) is the same size as A and has random entries.

randn('seed') returns the current value of the seed used by the generator.

randn('seed',n) sets the seed to n. randn('seed',0) sets the seed to its startup value.

randn with no arguments is a scalar whose value changes each time it is referenced.

The functions rand and randn maintain separate generators with separate seeds.

Examples

If randn has not yet been used during a particular MATLAB session, then R = randn(3,4) produces

 R =
    1.1650    0.3516    0.0591    0.8717
    0.6268   -0.6965    1.7971   -1.4462
    0.0751    1.6961    0.2641   -0.7012
For a histogram of the randn distribution, see hist.

Algorithm

randn uses a second copy of the uniform generator used by rand and transforms the resulting values according to the algorithm in [1].

See Also

rand, randperm

References

[1] G.E. Forsythe, M.A. Malcolm and C.B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1977.

(c) Copyright 1994 by The MathWorks, Inc.