From: Stephen Waits Date: 2005-12-07T05:04:13+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby Stephen Waits wrote: > I forgot to deal with collisions in the hash! :( Here's another shot.. still faster than sort_by{rand} on my system, and now should be unbiased: def shuffle3 h = Hash.new self.each do |v| k = rand(1000000000) until !h.has_key?(k) h[k] = v end end shuffle3 (10000) 3.625000 0.016000 3.641000 ( 3.656000) sort_by (10000) 5.250000 0.000000 5.250000 ( 5.312000) --Steve