From: Joel VanderWerf Date: 2009-01-27T05:08:57+09:00 Subject: Re: Separate random number generators? Bart Braem wrote: > Do not use ISAAC, running this simple test: > > rng = Crypt::ISAAC.new > res = Hash.new() > 1.upto(100000) do |i| > random = rng.rand > larger = (random * 10).to_i > res[larger] ||= 0 > res[larger] += 1 > end > 1.upto(10) do |i| > puts "hits for #{i}: #{res[i]}" > end > > Shows a large bias towards numbers below 0.4, unless I have an error > in this simple script of course. > rb-gsl gives problems with installation, I am going to try the Drb > solution. I use my own wrapper around Bob Jenkins' ISAAC library. Based on his comments on ruby-talk a few years ago, I chose to use the 256 rather than 16 entry state vectors (it turns out not to affect performance). It's served well for simulation purposes. Your code, modified slightly, gives the following results: hits for 0: 10213 hits for 1: 9830 hits for 2: 9902 hits for 3: 9928 hits for 4: 9951 hits for 5: 10111 hits for 6: 10012 hits for 7: 9940 hits for 8: 9896 hits for 9: 10217 Here's the example: require 'isaac' rng = ISAAC.new #rng.srand([...]) seed with up to 256 entries (optional) res = Hash.new() 1.upto(100000) do |i| # 100000 random = rng.rand larger = (random * 10).to_i res[larger] ||= 0 res[larger] += 1 end 0.upto(9) do |i| puts "hits for #{i}: #{res[i]}" end The extension is at: http://redshift.sourceforge.net/isaac-0.1/ -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407