From: Eero Saynatkari Date: 2006-01-25T05:35:29+09:00 Subject: Re: problems with standard rand functions Matthew Moss wrote: > hist = Hash.new(0) > 1_000_000.times do |i| > hist[rand(6)] += 1 > end > > print hist.map { |k,v| "#{k}:#{v}\n" }.sort.join > > > My output: > > 0:166636 > 1:166867 > 2:166866 > 3:166923 > 4:166572 > 5:166136 > > Seems pretty uniform to me... > As I recall (and someone else might know better), Ruby uses the > Mersenne Twister which is pretty darn random. I haven't seen the Ruby > source to know how they're presenting it (ie, how they map to a range > of 0-5, for instance) It is MT, indeed, but apparently the amount of bits actually used from the randomization is limited which slightly reduces the randomness. http://eigenclass.org has some further info. E -- Posted via http://www.ruby-forum.com/.