class Interval def initialize(min = Float::INFINITY, max = -Float::INFINITY) @min = min.to_f @max = max.to_f end attr_reader :min, :max def size @max - @min end def include?(x) min <= x && x <= max end def surround?(x) min < x && x < max end def sample rand(@min...@max) end def clamp(x) return @min if x < @min return @max if x > @max x end end