Re: Gaussian random variable



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
.



Relevant Pages

  • Re: Confidence interval
    ... mean will be 0 and standard deviation is 1. ... distribution for tolerance limits and acceptability. ... Your opinion IS the method, whether you call it mathematical or not. ... Bayesian statistics is based on the PERSONAL or SUBJECTIVE ...
    (sci.stat.consult)
  • Re: random numbers from a lognormal distribution
    ... >Shouldn't that be "If X is a standard normal variate then ... and standard deviation from the normal distribution to the lognormal ... functions, and for any non-decreasing function g, the percentiles ... In particular, if m is the median of a normal distribution, then ln ...
    (sci.stat.math)
  • Re: Thoughts on some stdlib modules
    ... makes no sense to make the Python standard distribution like this. ... not an OS and cannot control all of the little factors that make package management feasible for ... As a side note, with the Numeric/numarray unification, the Numeric ...
    (comp.lang.python)
  • Re: question about random generator
    ... >>> uniform distribution. ... >> What I was trying to explain is that pseudo-random does not imply ... >> anything about the distribution of the numbers. ... Well I don't know the standard by hard, ...
    (comp.lang.c)
  • Re: question about random generator
    ... >> The C Standard specifies that randgenerates pseudo-random numbers, ... >> the intention is that the numbers be uniform but that may be debatable. ... > anything about the distribution of the numbers. ...
    (comp.lang.c)