bo*@coolgroups.com wrote:
I was wondering if anyone can recommend a way to generate a Gaussian
random variable with standard deviation 1.
Thank you.
Nothing C++ about this question. Followups set to comp.programming.
Here's one very general approach that can also be applied to your question:
For a general distribution D(x) consider the integral of that
distribution G(x) = integral_{-infinity}^x D(y) dy. The range of G(x)
is then [0,1]. Pick a value z uniformly at random in [0,1] and consider
the inverse function G^{-1}(z). Then the distribution of values of
G^{-1}(z) obeys the original distribution D.
That may sound complicated but it's really not. You have a standard
normal distribution N(x). Integrate that distribution to get:
f(x) = 1/2 (1 + erf(x/sqrt(2))).
Now pick values uniformly at random in [0,1], which ought to be easy
(approximately) in most languages. Then compute f-inverse of those
values to get values obeying a Gaussian distribution. The hard part
here will be inverting the erf function. You'll probably have to rely
on some sort of library for this (or numerically integrate N(x) yourself
and create a lookup table of values of f(x)).
Mark