import random


def pick_event(event_intervals):
    """
    Returns a randomly selected index of an event from a list of intervals
    proportional to the events' probabilities

    :param event_intervals: list of event intervals
    """
    i_event = 0
    cumul_intervals = []
    cumul_interval = 0.0
    for interval in event_intervals:
        cumul_interval += interval
        cumul_intervals.append(cumul_interval)
    i = random.random() * cumul_interval
    i_last_event = len(event_intervals) - 1
    while i > cumul_intervals[i_event] and i_event < i_last_event:
        i_event += 1
    return i_event