From: Joel VanderWerf Date: 2002-04-04T14:28:57+09:00 Subject: Re: random numbers with a particualr statistical distribution Damien Joly 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. I ported the NR routines to Ruby, and used them in a Monte Carlo framework that takes a command line app of some sort and does a sequence of Monte Carlo simulations using it. It supports exponential, gaussian, log normal, uniform, and discrete distributions. The only problem is you need a license to use the NR algorithms ]:( feh! (The driver framework is nice in that you have a high level syntax (Ruby, in fact) in which you declare your variables and their characteristics, and the MC driver samples the distributions, substitutes the resulting values into the parameter files of the executable app, runs the app, collects output files, applies some pattern matching that you specify to collect data, and logs the extracted data for each run.) Another option is GSL--there appear to be two Ruby bindings on RAA--but then you have to be willing to use GPL. There's also Robert Feldt's RandomR, which is an implementation of the very interesting Mersenne Twister, which has nice speed and randomness properties, also GPL. I don't know if that includes any special prob. distributions, though.