# How can I generate half-normal variates in MATLAB?

I can find the

random('normal', 0, 1, 10000,1)


command in MATLAB but it generates half-normal variates. I would like to generate random half-normal variates. The half-normal distribution is defined by

$$f_{|Z|}(x)=\frac{2}{\sqrt{2\pi}}e^\frac{-x^{2}}{2}.$$

Can I generate a random half-normal variates from random normal variates?

-

As Wikipedia says, you can just compute a normally distributed random variable with a mean of zero and take the absolute value. The half-normal probability distribution function is identical to the normal PDF with $\mu = 0$ for $X > 0$, except for a factor of two for the normalization.