|MATLAB Function Reference|
Normally distributed random numbers and arrays
randn function generates arrays of random numbers whose elements are normally distributed with mean 0, variance , and standard deviation .
Y = randn(n)
n matrix of random entries. An error message appears if
n is not a scalar.
Y = randn(m,n) or Y = randn([m n])
n matrix of random entries.
Y = randn(m,n,p,...) or Y = randn([m n p...])
generates random arrays.
returns an array of random entries that is the same size as
Y = randn(size(A))
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:
||Resets the state to
||Resets the generator to its initial state.
||Resets it to a different state each time.
randn(3,4) may produce
For a histogram of the
randn distribution, see
Example 2. Generate a random distribution with a specific mean and variance . To do this, multiply the output of
randn by the standard deviation , and then add the desired mean. For example, to generate a 5-by-5 array of random numbers with a mean of .6 that are distributed with a variance of 0.1