Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

Generating random numbers from any given distribution

  • To: mathgroup at
  • Subject: Generating random numbers from any given distribution
  • From: "NELSON M. BLACHMAN" <blachman at>
  • 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

  • Prev by Date: Questions about rules
  • Next by Date: Excel and Mathematica?
  • Previous by thread: Questions about rules
  • Next by thread: Excel and Mathematica?