Re: how to get random numbers from a distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg81474] Re: how to get random numbers from a distribution
- From: dh <dh at metrohm.ch>
- Date: Wed, 26 Sep 2007 06:23:44 -0400 (EDT)
- References: <fd7s2q$cfd$1@smc.vnet.net>
Hi, here is a simple and general method. Assume we have a random variable in the range {lb,ub}. Further, p is the probabilitiy density function in the same range. This means: Integral p[x],{x,lb,ub}]==1. Then we can get the next random number with the chosen distribution by: next[p_,ub_,lb_]:=Module[{t}, While[p[t=Random[Real,{lb,ub}]]<Random[Real,{lb,ub}]]; t] here is a Gaussian example in the range {0,2}: p[x_]=Exp[-x^2]/Integrate[Exp[-x^2],{x,0,2}] hope this helps, Daniel tdoxmail at gmail.com wrote: > Hi ya alll > > I am a new Mathematica user. > I have a function that i use to generate a probability distribution > (eg x^2). I want a random number generator, that should generate > values from this probability distribution only, > > I know this Random function in mathematica, that can generate in > particular range, but how do i tell to generate from a particular > distribution. > > I created a list of values using my probability function but not able > to integrate it with Random function so that random numnber takes > value from that list. > > Also I googled and saw some function like RandomChoice and some other > but they are available in Mathematica6 and i use 5.2. > > Can u help with this. > > Thanks in advace > >