Class: Object

Inherits:
BasicObject
Defined in:
lib/just_enumerable_stats.rb

Overview

Borrowed this from my own gem, sirb

Instance Method Summary collapse

Instance Method Details

#rand_between(a, b) ⇒ Object

Simpler way to handle a random number between to values

[View source]

19
20
21
22
23
# File 'lib/just_enumerable_stats.rb', line 19

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

[View source]

26
27
28
29
# File 'lib/just_enumerable_stats.rb', line 26

def rand_in_floats(a, b)
  range = (a - b).abs
  (rand * range) + [a,b].min
end