From: Joel VanderWerf Date: 2004-08-15T06:00:48+09:00 Subject: Re: Random variable library? Mike wrote: > Martin DeMello wrote: > > >>>Anyone know of a Ruby library that defines random variables[1]? I'd like >>>access to a variety of distributions. > > >>http://users.rcn.com/m3ha11/ruby/Rand.rb looks good to me > > > Heh... I was going to say that. :-) > > It's just a collection of various distributions that I've seen in different places. > Like Joel said, it starts with Kernel.rand, so it's ultimately no better than that. > But, it should give you different distributions that you need. Not that there's anything wrong with Kernel.rand--it uses MT19937, which seems to be very good for all but crypto purposes.[1] That plus Rand.rb would be ideal for a single stream sampled from one of the many distributions that Rand.rb implements. With caution, you could use it for a small number of streams, too. It's just that if you need arbitrarily many streams of numbers, then you want to be able to instantiate more generators. Actually, I suppose you could use Kernel#srand to switch between streams. That would be slow, because the state vector has to be recreated each time, but would save on the space needed for all those state vectors. [1] http://en.wikipedia.org/wiki/Mersenne_twister