Qu

randn

Builtin index · Statistics & ML

result = randn([rows], [cols], [seed=])

Input: rows, cols, seed · Output: result

What it is

Draws from the standard normal distribution (mean 0, std 1), same rows/cols/seed= shape as rand.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = randn([rows], [cols], [seed=])
rows optionalnot documented yet
cols optionalnot documented yet
seed optionalnot documented yet
result number, vector, or matrix
Returns a number, vector, or (rows, cols) matrix.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

X    = randn(120, 3, seed = 3)   # 120 samples, 3 features

beta = [2.0, -1.0, 0.5]
y    = X * beta + 0.1 * randn(120, seed = 4)
Xnew = randn(30, 3, seed = 5)
ynew = Xnew * beta

from statistics-ml

boxplot(randn(50, seed = 20))
-3 -2 -1 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 x=0, y=0 x=1, y=0.479 x=2, y=0.841 x=3, y=0.997 x=4, y=0.909 x=5, y=0.598 x=6, y=0.141 x=7, y=-0.351 x=8, y=-0.757 x=9, y=-0.978 Styled panel

from plotting

boxplot(randn(50, seed = 20), randn(50, seed = 21) + 0.5, randn(50, seed = 22) - 0.3)
-3 -2 -1 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 x=0, y=0 x=1, y=0.479 x=2, y=0.841 x=3, y=0.997 x=4, y=0.909 x=5, y=0.598 x=6, y=0.141 x=7, y=-0.351 x=8, y=-0.757 x=9, y=-0.978 Styled panel

from plotting

noisy = signal + 0.3 * randn(1000, seed = 1)
print("clean {rms(signal):.3f}, noisy {rms(noisy):.3f}")
output
clean 0.707, noisy 0.768

from start-here

How it works

rand/randn draw rows*cols samples. An explicit seed= gives a fresh reproducible local stream; otherwise the persistent stream advances so successive draws differ.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.