from typing import List
from typing import Tuple
import random


def draw_indexed(index_prob: List[Tuple[int, float]]):
    """
    Draw from a discrete random variable with mass at second position in tuple in list `index_prob`.
    Indices returned are at first position in tuples.
    """
    # Generate random number in the interval [0, 1)
    k_uni = random.random()

    for i, prob in index_prob:
        # Subtract while there is mass left
        k_uni -= prob
        if k_uni < 0:
            return i

    return index_prob[-1][0]