def weighted_choice(weights, prng):
    """Samples from a discrete distribution.


    Parameters
    ----------
    weights : list
        A list of floats that identifies the distribution.

    prng : numpy.random.RandomState
        A pseudorandom number generator object.


    Returns
    -------
    int
    """
    rnd = prng.rand() * sum(weights)
    n = len(weights)
    i = -1
    while i < n - 1 and rnd >= 0:
        i += 1
        rnd -= weights[i]
    return i