Re: Gaussian random variable
- From: Lionel B <me@xxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 13:22:25 +0000 (UTC)
On Fri, 30 Mar 2007 08:16:26 +0000, Mark P wrote:
bob@xxxxxxxxxxxxxx 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)).
That is likely to be an /extremely/ inefficient way to do it.
Simple to code up and pretty fast is the standard Box-Muller method:
http://en.wikipedia.org/wiki/Box-Muller_transform
--
Lionel B
.
- Follow-Ups:
- Re: Gaussian random variable
- From: user923005
- Re: Gaussian random variable
- Prev by Date: Seeking URL code for this functionality
- Next by Date: Looking for a *FAST* graphics library
- Previous by thread: Seeking URL code for this functionality
- Next by thread: Re: Gaussian random variable
- Index(es):
Relevant Pages
|