import random


def _pick_split_point(p_span, p_config):
    """
    Picks a point at which to split the specified span into two 'intervals' [a, b) and [b, c).
    Return value is b, i.e. exclusive for first interval, inclusive for second.
    Returns -1 if the span is not wide enough to fit two new rooms with any split.
    """
    #new rooms each need at least p_config.min_span tiles
    if p_span < (p_config.min_span + p_config.min_offset * 2) * 2:
        return -1
    min = p_config.min_span + 2 * p_config.min_offset
    max = p_span - p_config.min_span - 2 * p_config.min_offset
    return random.randint(min, max) if min != max else min