class Array
  
  def get_rand(arr)
    raise "Wrong number of arguments" unless arr.size == self.size
 #   raise "Currently working only for arrays smaller then 200 elements" if arr.size > 199
    total = arr.inject { |x, y| x+y }
    hash = { }
    counter = (arr.size / 100)+ 1
    self.each_with_index do |arg, i|
      hash[arg] = ((arr[i].to_f / total.to_f) * counter * 100).round
    end
    array_to_load = []
    hash.each_pair do |k,v|
      v.times do 
        array_to_load << k
      end
    end
    value = rand(3) - 1
    array_to_load.sort { |x,y| rand(3)-1 }.first
  end
  
end
class Array
  def get_rand(weights)
    raise "Wrong number of array elements!" unless weights.size == self.size

    total = weights.inject(0, :+)
    point = Kernel.rand * total

    self.each_with_index do |element, i|
      return element if weights[i] >= point
      point -= weights[i]
    end
  end
end

Rewrite get_rand method - less LOC, better alhorithm, names.
Rewrite get_rand method - less LOC, better alhorithm, names.

Complexity is now O(N), where N is number of array elements.
