import random


def choose_next(transitions):
    """
    Select the next element from probability dict.

    The dict should have the form of ``{element: probability}``, ie
    ``{'e1': 0.5, 'e2': 0.1, ...}``. Assumes that probabilities sum to unity.
    :param transitions: Probability dict
    :return: element ID
    """
    roll = random.random()
    total = 0
    for element in transitions:
        total += transitions[element]
        if total >= roll:
            return element