From: "David A. Black" Date: 2008-07-04T01:15:50+09:00 Subject: Re: pseudo-randomize an array in a consistent order Hi -- On Fri, 4 Jul 2008, James Gray wrote: > On Jul 3, 2008, at 11:08 AM, 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] > > Oh, you meant to show this behavior. My bad. It's not really even pseudo-random, though -- it's just what you get if you always say that a <=> b is > 0. [1,2,3,4,5].sort { 1 } does the same thing. So every 5-element array will shuffle the same way, which I don't think is what the OP wanted. 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!