def discrete_sequence(n, distribution=None, cdistribution=None):
    import bisect

    if cdistribution is not None:
        cdf=cdistribution
    elif distribution is not None:
        cdf=cumulative_distribution(distribution)
    else:
        raise nx.NetworkXError(
                "discrete_sequence: distribution or cdistribution missing")
        

    # get a uniform random number
    inputseq=[random.random() for i in range(n)]

    # choose from CDF
    seq=[bisect.bisect_left(cdf,s)-1 for s in inputseq]
    return seq
Return sample sequence of length n from a given discrete distribution
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/utils/random_sequence.py/discrete_sequence