Hacker News new | ask | show | jobs
by CamperBob2 1807 days ago

    function generate_candidates(;n=1)
        return 100 .+ (15 .* randn(n, 1))
    end
How does this yield a Gaussian distribution?
1 comments

`randn` returns draws from a standard normal distribution (i.e., a Gaussian with mean 0 and standard deviation 1); the n is for normal.

It's then stretched to have an SD of 15 via multiplication, and shifted to have a mean of 100.

This is Julia, but it's the same in Matlab and Numpy (np.random.randn); it'd be rnorm in R (which also lets you specify the mean and sd directly).

Ah, thanks, I was reading it as "random number."