import logging


def split_list(source_list, splitter_algo: str, splitter_args, randomizer):
    """
    Removes a set of items from the source list and returns them in a new list based on the
    splitter algorithm and splitter_args;
    :param source_list: The source list to split.  It is MODIFIED.
    :param splitter_algo: The algorithm to use to split out the data
    :param splitter_args: The arguments to the splitting algorithm.
    :param randomizer: Randomizer if needed
    :return: The elements removed out of the source list.
    """
    shard = []
    if splitter_algo == 'randomFraction':
        count = round(len(source_list) * float(splitter_args['fraction']))
        val_indexes = randomizer.sample(range(0, len(source_list)), count)
        val_indexes = sorted(val_indexes, reverse=True)

        for i in val_indexes:
            shard.append(source_list[i])
            del (source_list[i])
    else:
        logging.error(f"Unknown validation algorithm '{splitter_algo}', not splitting list.")

    return shard