code: def sample_uniform(in_range, seed_coins):
      
      if isinstance(seed_coins, list):
          seed_coins.append(None)
          seed_coins = iter(seed_coins)
      cur_range = in_range.copy()
      assert cur_range.size() != 0
      while cur_range.size() > 1:
          mid = (cur_range.start + cur_range.end) // 2
          bit = next(seed_coins)
          if bit == 0:
              cur_range.end = mid
          elif bit == 1:
              cur_range.start = mid + 1
          elif bit is None:
              raise NotEnoughCoinsError()
          else:
              raise InvalidCoinError()
      assert cur_range.size() == 1
      return cur_range.start
docs: Uniformly select a number from the range using the bit list as a source of randomness