Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/model_grinder/ruby_hacks.rb
Overview
:nodoc: all
Instance Method Summary collapse
Instance Method Details
#sample(num = 1) ⇒ Object
:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/model_grinder/ruby_hacks.rb', line 3 def sample(num = 1) #: ret = [] already_picked = [] (1..num).each { |i| break if i > length i2 = rand(length - 1) while already_picked.include?(i2) i2 = rand(length - 1) end already_picked << i2 ret << self[i2] } ret end |