def weighted_choice(mapping):
    # use roulette method
    rnd = random.random() * sum(mapping.values())
    for k, w in mapping.items():
        rnd -= w
        if rnd < 0:
            return k
Return a single element from a weighted sample.
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/utils/random_sequence.py/weighted_choice