Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/just_enumerable_stats.rb,
lib/just_enumerable_stats/stats.rb
Overview
This is a namespaced version of the gem, in case you can create a container for your data and only include these methods there. Example:
Instance Method Summary collapse
-
#rand_between(a, b) ⇒ Object
Simpler way to handle a random number between to values.
-
#rand_in_floats(a, b) ⇒ Object
Handles non-integers.
Instance Method Details
#rand_between(a, b) ⇒ Object
Simpler way to handle a random number between to values
10 11 12 13 14 |
# File 'lib/just_enumerable_stats.rb', line 10 def rand_between(a, b) return rand_in_floats(a, b) if a.is_a?(Float) or b.is_a?(Float) range = (a - b).abs + 1 rand(range) + [a,b].min end |
#rand_in_floats(a, b) ⇒ Object
Handles non-integers
17 18 19 20 |
# File 'lib/just_enumerable_stats.rb', line 17 def rand_in_floats(a, b) range = (a - b).abs (rand * range) + [a,b].min end |