def chooseFromDistribution(distribution):
    if isinstance(distribution, dict) or isinstance(distribution, Counter):
        return sample(distribution)
    r = random.random()
    base = 0.0
    for prob, element in distribution:
        base += prob
        if r <= base:
            return element
Takes either a counter or a list of (prob, key) pairs and samples
dataset/ETHPy150Open rlpy/rlpy/rlpy/Domains/PacmanPackage/util.py/chooseFromDistribution