On 2008-07-03, Max Williams <toastkid.williams / gmail.com> wrote:
> class Array
>
>   def randomize(seed=nil)
>    srand(seed) if seed
>    self.sort{|a,b| rand <=> rand }
>   end

I would suggest using sort_by { |a| rand }

Otherwise, you could trigger a pathological case if the algorithm depends
on the assumption that every comparison of any two elements will yield the
same results.  (sort_by caches the values it generates, so that doesn't
happen.)

-- 
Copyright 2008, all wrongs reversed.  Peter Seebach / usenet-nospam / seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!