def choice(r,p_cumsum):
    """ select from cumulated probilities 

    Args:

        r (double): uniform random number
        p_cumsum (numpy.ndarray): vector of cumulated probabilities, [x,y,z,...,1] where z > y > x > 0

    Returns:

        i (int): selection index

    """

    i = 0
    while r > p_cumsum[i] and i+1 < p_cumsum.size:
        i = i + 1

    return i