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.
| Code | Input | Output | Description |
result = randn([rows], [cols], [seed=]) | rows optionalnot documented yetcols optionalnot documented yetseed 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))
from plotting
boxplot(randn(50, seed = 20), randn(50, seed = 21) + 0.5, randn(50, seed = 22) - 0.3)
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.