www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/22/13:05:59

From: broeker AT acp3bf DOT knirsch DOT de (Hans-Bernhard Broeker)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: randN
Date: 22 Nov 1999 15:04:13 +0100
Organization: RWTH Aachen, III. physikalisches Institut B
Lines: 30
Message-ID: <81bigt$1i5@acp3bf.knirsch.de>
References: <383904BA DOT AE45DCDE AT mpx DOT com DOT au>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 943279455 21604 137.226.32.75 (22 Nov 1999 14:04:15 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 22 Nov 1999 14:04:15 GMT
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019