def _threshold_calc(random_edge, max_edge, vertex_degree):
    """
    Calculate threshold for branch_gen function.

    :param random_edge: number of vertex edges
    :type random_edge: int
    :param max_edge : maximum edge number
    :type max_edge : int
    :param vertex_degree: vertex degree
    :type vertex_degree: int
    :return: threshold as int
    """
    threshold = min(random_edge, abs(max_edge - vertex_degree))
    return threshold