Re: random numbers from user-defined distributions
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: random numbers from user-defined distributions
- From: jacobson at cello.hpl.hp.com
- Date: Thu, 07 Jan 93 08:31:32 -0800
Dr. Robert B. Nachbar asks does anyone know how to use Random with an arbitrary distribution function? i would like to generate random numbers in the range {0, Pi} with a probability distribution function (PDF) of Sin[x]. The standard technique is to take the inverse cumulative distribution function and apply it to a random number in the range 0-1. So in your case the cumulative distribution is given by In[4]:= Integrate[Sin[xx],{xx,0,x}]/Integrate[Sin[xx],{xx,0,Pi}] 1 - Cos[x] Out[4]= ---------- 2 So your function is ArcCos[1-2 Random[]], or alternatively, ArcCos[Random[Real,{-1,1}]] -- David Jacobson