From: "Eric I." Date: 2008-07-04T03:56:54+09:00 Subject: Re: pseudo-randomize an array in a consistent order On Jul 3, 11:57 am, Max Williams wrote: > This is what i did in the meantime since asking (I monkey-patched > Array): > > class Array > >   def randomize(seed=nil) >    srand(seed) if seed >    self.sort{|a,b| rand <=> rand } >   end > >   def randomize!(seed=nil) >    srand(seed) if seed >    self.sort!{|a,b| rand <=> rand } >   end > > end Hi Max, How about a very small change: class Array def randomize(seed=nil) srand(seed) if seed sort_by { rand } srand # re-seed random number generator end def randomize!(seed=nil) replace(randomize(seed)) end end Because the seed used to generate random values (via Kernel#rand) is global, if you switch it back, you'll (likely) affect random numbers across your entire Ruby instance. I don't know if this will have any effect on your current project, but should you ever integrate this technique on another project, it could cause a problem. Eric ==== LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE workshops. Please visit http://LearnRuby.com for all the details.