Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/generator.rb
Overview
Some nasty Array-Monkeypatches
Instance Method Summary collapse
- #rand ⇒ Object
-
#randn(n) ⇒ Object
works like rand, but returns n random elements from self if n >= self.lenth, self is returned.
Instance Method Details
#rand ⇒ Object
3 4 5 |
# File 'lib/generator.rb', line 3 def rand self[Kernel.rand(length)] end |
#randn(n) ⇒ Object
works like rand, but returns n random elements from self if n >= self.lenth, self is returned
9 10 11 12 13 14 15 16 17 |
# File 'lib/generator.rb', line 9 def randn(n) return self if n >= length ret = [] while (ret.length < n) do dummy = rand ret << dummy unless ret.member?(dummy) end ret end |