Mail Archives: djgpp/1999/11/22/13:05:59
infinity girl (entropic AT mpx DOT com DOT au) wrote:
> i'm wondering if anyone has written {or come across} C functions
> that produce random numbers under a Gaussian {normal} distribution?
> In other languages they are usually called randn or randg.
'Other languages'; you're sure? I don't think I ever saw a programming
*language* that has gaussian-distributed pseudo random numbers in its
definition of 'must-have' library functions. Not even Fortran is
*that* complete, in the language itself. Particular compiler or system
vendors may have included such functions in their math libraries, but
none of that is standardized, AFAIK.
> it is quite a common thing..has anyone thought about possibly
> including functions like this in libm?
No need to, really. Gaussian-distributed randoms can be generated from
flat distributions, by well-known standard techniques. Source code of
that kind is generally found in text books (like those on 'Monte Carlo
techniques'), or in the NetLib repository (http://www.netlib.org).
The typical method works by transforming the distribution. The trick
is that the cumulative version of any distribution is equally
distributed between 0.0 and 1.0, i.e. you can randomly choose a
'percentile', and map that back to a value distributed as prescribed,
by the inverse of the cumulative distribution function (the 'inverse
error function', in the case of Gaussian).
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -