From: Armin Roehrl Date: 2002-04-11T18:36:59+09:00 Subject: Re: random numbers with a particualr statistical distribution What specific distribution do you need? F(^-1)(U) is your friend, where U~uniform and F(^-1) is the inverse. Bye, A On Thursday 04 April 2002 00:35, you wrote: > Has anyone out there written code in Ruby to generate > random numbers with a particular statistical > distribution. I know algorithms exist in C/C++: > > http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf/c7-2.pdf > > and > > http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf/c7-3.pdf > > But it would be handy to have the common distributions > available in Ruby. Generating a random deviate with > mean = x and standard deviation = y is easy (see > below), but the other distributions can get quite > ugly. > > Thanks, > > Damien > > def norm(mean,sd) > mean+(Math.log10((1+(2*rand()- > 1))/(1-(2*rand()-1)))/1.82)*3*sd > end > > a = norm(x,y) > > __________________________________________________ > Do You Yahoo!? > Yahoo! Tax Center - online filing with TurboTax > http://taxes.yahoo.com/ -- Armin. ----------------------------------------------- Armin Roehrl, http://www.approximity.com Training, Development and Mentoring OOP, XP, Java, Ruby, Smalltalk, Datamining, Parallel computing, Webservices Koautor des ersten dt. Rubybuches http://approximity.com/rubybuch/ Naechster Rubyseminar: 9/9-11/9 in Hamburg. You have all eternity to be cautious in when you're dead. -- Lois Platford