import random


def sample(probas):
    """
    Sample a discrete proba law given as 1D array
    :param probas: 1D discrete probabilities distribution np.sum(probas) = 1
    :return: One sample according probas
    """
    u = random.random()
    index = 0
    acc = probas[index]
    while acc < u:
        index += 1
        acc += probas[index]
    return index