Kirk Haines wrote: > This is to announce the release of Crypt::ISAAC, a pure Ruby implementation > of the ISAAC psuedo-random number generator. ISAAC is an algorithm for > generating cryptographically secure psuedo-random numbers. This library has > been part of the Iowa package for a couple of years. This version will > become the canonical version, however. > > Crypt::ISAAC can be used to setup multiple independent streams of random > numbers, and offers a simple interface identical to that of Kernel.rand(): > > > require 'crypt/isaac' > > rng1 = Crypt::ISAAC.new > rng2 = Crypt::ISAAC.new > > ri1 = rng1.rand(1000000) > ri2 = rng2.rand(1000000) > rf1 = rng1.rand > rf2 = rng2-rand > > puts "#{ri1} -- #{ri2}" > puts "#{rf1} -- #{rf2}" > > > I am releasing the library as version 0.9 just because while I have been > using it for a couple of years, nobody else has ever looked at it, so there > may well be some tweaks and nudges to bits of it before I call it 1.0. Thanks for that, Kirk. But I think I will need repeatability (as with Kernel#srand), for use in simulations, and also speed. So I kludged up a extension at http://redshift.sourceforge.net/isaac. It's public domain, just like the original ISAAC. One difference: since I am interested in simulations, I followed Jenkins' advice and set the state vector length to 16 longs rather than 256 (smaller, faster, less secure). In the next iteration, I will make this selectable from the API. It's not well tested, but usage is: [ruby/prj/isaac/ext/isaac] irb -r isaac.so irb(main):001:0> r = ISAAC.new => #<ISAAC:0x40208aa0> irb(main):002:0> r.srand [234,546,7868,98] => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] irb(main):003:0> r.rand32 => 413434623 irb(main):004:0> r.rand32 => 1012446849 irb(main):005:0> r.rand32 => 3846288904 The input (and output) of #srand is an array of up to 16 longs used to seed the generator. Also in the next version: float output, distributions as in the Rand.rb that someone pointed out, better namespace, etc.