def _sample_ncols(col_limits, random_state):
    """ Sample a valid number of columns from the column limits. """

    integer_limits = []
    for lim in col_limits:
        try:
            integer_lim = sum(lim)
        except TypeError:
            integer_lim = lim
        integer_limits.append(integer_lim)

    return random_state.randint(integer_limits[0], integer_limits[1] + 1)