Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Answer: How do I get random numbers that follow standard distribution?

by chas (Priest)
on Feb 16, 2005 at 19:30 UTC ( #431699=categorized answer: print w/replies, xml ) Need Help??

Q&A > math > How do I get random numbers that follow standard distribution? - Answer contributed by chas

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

  • Comment on Answer: How do I get random numbers that follow standard distribution?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-10-27 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (258 votes). Check out past polls.

    Notices?