import random


def randomdiscrete(probs):
    """
    Takes a list of probabilities that should sum to one, and returns a random
    list index according to the probabilities in the list.
    """
    n = len(probs) - 1
    acc = 0.0
    ind = -1
    r = random.random()
    while acc <= r and ind < n:
        ind += 1
        acc += probs[ind]
    return ind