[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:03:00 AM

In message <55DCC0B4-DF5C-4D70-99E8-78D1572DDD16@sbcglobal.net>, Gary Wright writes:
>On Apr 29, 2007, at 10:28 PM, Peter Seebach wrote:

>> l = a.length
>> a.each_index { |x| a[x] = a[rand(l)] }

>You are trashing your original array.

True.

That said, with the apparent speed difference, it's probably worth
copying and then shuffling.

-s