import random


def estimate_occ_per_ap(prob_dist=[0.405, 0.345, 0.125, 0.092, 0.033]):
    """
    Randomly generates a number of occupants between 1 and 5

    Parameters
    ----------
    prob_dist : list (of floats), optional
        Defines probability distribution of occupants per apartment
        Default: [0.405, 0.345, 0.125, 0.092, 0.033]
        Based on data of Statistisches Bundesamt (2012)
        https://www.destatis.de/DE/ZahlenFakten/Indikatoren/LangeReihen/Bevoelkerung/lrbev05.html;jsessionid=4AACC10D2225591EC88C40EDEFB5EDAC.cae2

    Returns
    -------
    nb_occ : int
        Number of occupants within one apartment
    """

    #  Generate random float between 0 and 1 (0 and 1 included!)
    rand_val = random.randint(0, 100000) / 100000

    if rand_val < prob_dist[0]:
        nb_occ = 1
    elif rand_val < prob_dist[0] + prob_dist[1]:
        nb_occ = 2
    elif rand_val < prob_dist[0] + prob_dist[1] + prob_dist[2]:
        nb_occ = 3
    elif rand_val < prob_dist[0] + prob_dist[1] + prob_dist[2] + prob_dist[3]:
        nb_occ = 4
    else:
        nb_occ = 5

    return int(nb_occ)