[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: sorting by rand?

seebs

4/30/2007 3:02:00 AM

In message <deb2337a0704291937g7384a9bej381a99282460dc07@mail.gmail.com>, "Rick DeNatale" write
s:
>I believe that the "something to that effect was probably:
>
> x.sort_by {rand}

Yes.

>Perfectly safe as far as I can see.

Ahh! Yes. Profiling it reveals this; it only calls rand once per
element. Sane, and efficient.

>x.sort {rand}

I think I've seen also sort {rand <=> rand}, which is crazy.

-s