From: Florian Frank Date: 2007-01-03T06:02:55+09:00 Subject: Re: Randomizing an Array? Ilan Berci wrote: > jwcooper wrote: > >> I'm trying to randomize an array, and this is what I have: >> [...] > ilans-Mac:~ ilan$ irb > irb(main):001:0> (1..10).to_a.sort {rand} > => [10, 6, 1, 7, 3, 8, 5, 9, 4, 2] > irb(main):002:0> > Don't do this, better use (1..10).sort_by { rand }. Your version is equivalent to (1..10).sort { 1 } and *always* creates the same permutation for this array. -- Florian Frank