H
Hammed Malik
------=_Part_9539_13698596.1133466156105
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
I'd like to sort collections randomly. This is what I tried first:
my_array.sort { |a,b| rand(2) }
but the results weren't very random. I then tried the following:
class Array
This works but I'm sure there's some Ruby magic for doing this better.
thanks
------=_Part_9539_13698596.1133466156105--
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
I'd like to sort collections randomly. This is what I tried first:
my_array.sort { |a,b| rand(2) }
but the results weren't very random. I then tried the following:
class Array
def random_copy
b =3D Array.new
while b.length < self.length
random_value =3D self[rand self.length]
b.push random_value unless b.include? random_value
end
b
end
end
This works but I'm sure there's some Ruby magic for doing this better.
thanks
------=_Part_9539_13698596.1133466156105--