Perl Monk, Perl Meditation | |
PerlMonks |
Re: How do I get random numbers that follow standard distribution?by chas (Priest) |
on Feb 16, 2005 at 19:30 UTC ( [id://431699]=note: print w/replies, xml ) | Need Help?? |
By "standard distribution", I think you mean "standard Normal distribution". One way to get a
random sample from such a distribution is as follows: Get a random sample x_1,...x_n from a uniform distribution on the unit interval. (this is easily
done using the usual random number generators you refer to.) Then for each x_i, compute
z_i satisfying x_i=(1/sqrt(2 pi))\int_{-\infty}^z_i e^{-t^2/2}dt. (I.e. x_i=F(z_i) where F is the distribution function for a N(0,1).) Then z_1,...z_n will be a random sample from a N(0,1). You have to write a bit of code to solve for z_i, of course. I've done similar things in c, but not perl so I can't display perl code to achieve this. The previous suggestion to add the results of several uniformly distributed random numbers is interesting; one needs independence to make use of the Central Limit Theorem, so I'm not sure exactly how to set that up, but it should be possible. The method I described first is pretty standard. chas
In Section
Seekers of Perl Wisdom
|
|