Class: Object

Inherits:
BasicObject
Defined in:
lib/ext/object.rb

Instance Method Summary collapse

Instance Method Details

#rand_between(a, b) ⇒ Object

Simpler way to handle a random number between to values



4
5
6
7
8
# File 'lib/ext/object.rb', line 4

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



11
12
13
14
# File 'lib/ext/object.rb', line 11

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