Re: generating random number
- To: mathgroup at smc.vnet.net
- Subject: [mg34519] Re: generating random number
- From: "Raf" <r_a_f at yahoo.it>
- Date: Fri, 24 May 2002 02:42:37 -0400 (EDT)
- Organization: [Infostrada]
- References: <200205210628.CAA07798@smc.vnet.net> <acferi$rmd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"ester" <Ester.Piedipalumbo at na.infn.it> ha scritto nel messaggio news:acferi$rmd$1 at smc.vnet.net... > > dear Sirs, > my name is Ester Piedipalumbo and I am a post doc at the phisics dep. of > Naples University. > I would like to know if there is something for generating random number > according an arbitary PDF (where arbitrary means that it is not standard, > but I know, of cource) > Thank a lot > best regrds > Ester > > > A solution is Montecarlo method [una soluzione è il metodo Montecarlo]: a = 1; myPDF[x_] := x/a^2/E^(x^2/(2*a^2)) Plot[myPDF[x], {x, 0, 5}, PlotRange -> All] myCDF[x_] = Integrate[myPDF[t], {t, 0, x}] Plot[myCDF[x], {x, 0, 5}, PlotRange -> All] inv = x /. Solve[myCDF[x] == y, x][[1]] Plot[inv, {y, 0, 1}, PlotRange -> All] numCamp = 1000; gen = Table[y = Random[]; inv, {numCamp}]; ListPlot[gen] sor = ({#1[[1]], #1[[2]]/numCamp} & ) /@ Reverse /@ Transpose[{Range[numCamp], Sort[gen]}]; ListPlot[sor] Saluti, Raffaele.