code: def weighted_rand(weights, round_result=False):
      if len(weights) == 1:
          return weights[0][0]
      weights = sorted(weights, key=lambda w: w[0])
      x_min = weights[0][0]
      x_max = weights[-1][0]
      y_min = 0
      y_max = max([point[1] for point in weights])
      attempt_count = 0
      while attempt_count < 500000:
          sample = (random.uniform(x_min, x_max), random.uniform(y_min, y_max))
          if _point_under_curve(weights, sample):
              if round_result:
                  return int(round(sample[0]))
              else:
                  return sample[0]
          attempt_count += 1
      else:
          warnings.warn(
               'Point not being found in weighted_rand() after 500000 '
               'attempts, defaulting to a random weight point. '
               'If this happens often, it is probably a bug.')
          return random.choice(weights)[0]