```James Gray wrote:
> On Aug 26, 2007, at 12:31 PM, botp wrote:
>
>> On 8/26/07, Ken Bloom <kbloom / gmail.com> wrote:
>>> Whoops. As soon as I posted, I noticed that there is no sort_by!.
>>
>> try
>>
>>     sort!{rand}
>
> That's not a random sort.  In fact, it's equivalent to sort! { 1 }:
>
>  >> data = (0..9).to_a
> => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>  >> data.sort! { rand }
> => [9, 5, 0, 6, 2, 7, 4, 8, 3, 1]
>  >> data.sort! { rand }
> => [1, 7, 9, 4, 0, 8, 2, 3, 6, 5]
>  >> data.sort! { rand }
> => [5, 8, 1, 2, 9, 3, 0, 6, 4, 7]
>  >> data = (0..9).to_a
> => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>  >> data.sort! { 1 }
> => [9, 5, 0, 6, 2, 7, 4, 8, 3, 1]
>  >> data.sort! { 1 }
> => [1, 7, 9, 4, 0, 8, 2, 3, 6, 5]
>  >> data.sort! { 1 }
> => [5, 8, 1, 2, 9, 3, 0, 6, 4, 7]
>
> It would be better to use:
>
> data = data.sort_by {  }
>
> James Edward Gray II

Well, it has the (extremely little) chance of being 0, which introduces
a very very small randomness :)

Regards
Stefan
--
Posted via http://www.ruby-forum.com/.

```