From: "David A. Black" Date: 2008-07-04T01:08:59+09:00 Subject: Re: pseudo-randomize an array in a consistent order Hi -- On Fri, 4 Jul 2008, Max Williams wrote: > Thanks guys > > 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 > > I'm worried though that using sort like this is a bit inefficient. The > array being sorted is around 3000 numbers (and not likely to exceed > 5000) so maybe that's not too much of an issue. Is there a more > efficient way you can think of? I absolutely wouldn't worry about it, unless you actually notice any slowness. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails July 21-24 Edison, NJ Advancing With Rails August 18-21 Edison, NJ See http://www.rubypal.com for details and updates!