From: Robert Dober Date: 2008-07-04T03:37:43+09:00 Subject: Re: pseudo-randomize an array in a consistent order On Thu, Jul 3, 2008 at 6:08 PM, James Gray wrote: > On Jul 3, 2008, at 11:04 AM, Robert Dober wrote: > >> a.sort{ rand } > > Don't do that: > >>> a = (1..5).to_a > => [1, 2, 3, 4, 5] >>> a.sort { rand } > => [5, 3, 1, 4, 2] >>> a.sort { rand } > => [5, 3, 1, 4, 2] >>> a.sort { rand } > => [5, 3, 1, 4, 2] > > Use a.sort_by { rand } instead. > > James Edward Gray II > > James you should know me better ;) He does not want sort_by{ rand } he explicitely asked for deterministic results, thus sort{ rand }. But yet James is right of course, even if for the wrong reason here. First of all you cannot set the seed, second of all it will not be portable (jruby reverses for example, while ruby1.8 and ruby1.9 do the same right now), and I guess that this is not guaranteed behavior at all. So after all I have to admit it was not my brightest idea to introduce this "pattern" ;) OTOH I had worse ideas. Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- AALST (n.) One who changes his name to be further to the front D.Adams; The Meaning of LIFF