Posted By

rduv on 12/21/06


Tagged

shuffle


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


concentration studios 12 Days of Stupid Ruby Tricks


 / Published in: Ruby
 

URL: http://concentrationstudios.com/2006/12/20/12-days-of-stupid-ruby-tricks

  1. class Array def shuffle n = [] while !empty? n << delete_at(rand(size)) end n end end # Usage >> [1,2,3,4,5].shuffle => [2, 4, 5, 1, 3]

Report this snippet  

You need to login to post a comment.