Generating random numbers from any given distribution

*To*: mathgroup at yoda.physics.unc.edu*Subject*: Generating random numbers from any given distribution*From*: "NELSON M. BLACHMAN" <blachman at gtewd.mtv.gsc.gte.com>*Date*: Thu, 07 Jan 1993 14:07:47 PST

Bob Nachbar asks how to generate a random number x between 0 and Pi with a probability density function f[x] proportional to Sin[x]; i.e., f[x] = Sin[x]/2. The general solution is first to determine the associated cululative distribution function F[x] = Integrate[f[w],{w,-Infinity,x}], (1) which, in his case is F[x] = (1 - Cos[x])/2. (2) Then solve for x: x = G[F], where G[.] is the inverse of F[.]. In the case of (2), this is x = ArcCos[1 - 2F], and, finally, make F a random variable uniformly distributed between 0 and 1: F = Random[], x = G[ Random[] ]. In Bob's case, x = ArcCos[ 1 - 2 Random[] ]. Nelson M. Blachman GTE Government Systems Corp. Mountain View, California blachman#gtewd.mtv.gsc.gte.com