title: Random integer in a given weighted range
body: <p>I've build a generator returning a random integer in a given, weighted range, but I'm not that happy with how it looks:</p>
  
  <pre><code>from random import choices, randrange
  
  def gen_ranged_weighted_value(ranges, weights):
      while True:
          yield randrange(
             *choices(ranges, weights)[0]
          ) 
  </code></pre>
  
  <p>Is there a built in function for this? Can I write this one better? I wouldn't want to use numpy for such a a simple task.</p>
  
  <p>Also, is there an alternative for <code>random.choices</code> here? I would like to build a version working with Python 2.7.x</p>
  
  <p>usage example:</p>
  
  <pre><code>foo = gen_ranged_weighted_value([(18,22),(101,201)], [0.98, 0.02])
  
  for a in range(10):
      print(next(foo))
  </code></pre>