From: "Aleksi Niemelä" Date: 2000-07-03T21:45:16+02:00 Subject: [ruby-talk:03775] Array.pick I've found following snippet quite handy. Dunno if there's wider need for this. class Array def pick( count = -1 ) if count >= 0 ary = [] count.times do ary << self.delete_at( rand( self.length ) ) end return ary end self.delete_at( rand( self.length ) ) end end require 'xmp' xmp <<-EOS a = (0...10).to_a b = [] 3.times do b << a.pick end b a.pick(0) a.pick(1) a.pick(3) a EOS ################ Outputs: a = (0...10).to_a #=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] b = [] #=> [] 3.times do b << a.pick end #=> 3 b #=> [9, 3, 5] a.pick(0) #=> [] a.pick(1) #=> [7] a.pick(3) #=> [6, 0, 2] a #=> [1, 4, 8] Ps. guess why I found EOS\n -feature ?) - Aleksi