Florian Frank
1/2/2007 9:03:00 PM
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