Module: MoreCoreExtensions::ArrayRandom
- Defined in:
- lib/more_core_extensions/core_ext/array/random.rb
Instance Method Summary collapse
-
#random_element ⇒ Object
Picks an element randomly.
-
#random_index ⇒ Object
Picks a valid index randomly.
Instance Method Details
#random_element ⇒ Object
Picks an element randomly
[1, 2, 3, 4, 2, 4].random_element #=> any randomly selected element in Array
14 15 16 |
# File 'lib/more_core_extensions/core_ext/array/random.rb', line 14 def random_element self[self.random_index] end |
#random_index ⇒ Object
Picks a valid index randomly
[1, 2, 3, 4, 2, 4].random_index #=> random number between 0..5
6 7 8 |
# File 'lib/more_core_extensions/core_ext/array/random.rb', line 6 def random_index rand(self.size) end |