code: def random_variant(variants, weights):
      
      total = 0
      accumulator = []
      for w in weights:
          total += w
          accumulator.append(total)
  
      r = randint(0, total - 1)
      yield variants[bisect(accumulator, r)]
docs: A generator that, given a list of variants and a corresponding list of
      weights, returns one random weighted selection.