from typing import OrderedDict


def linear_set_generator(random, args):
    """
    Generates a list continuous values of the size of a representation.
    This function requires that a bounder is defined on the EvolutionaryAlgorithm.

    See Also
    --------
    inspyred.ec


    Parameters
    ----------
    random : Random
    args : dict
        representation: set containing the possible values
        max_candidate_size: int, default: 9
        variable_candidate_size: bool, default: True

    Returns
    -------
    list
        A list containing tuples - sample of the elements and linear value.
        If variable_candidate_size is True the list size is up to max_candidate_size,
        otherwise the candidate size equals candidate_size
    """
    bounder = args.get("_ec").bounder
    representation = args.get('representation')
    max_size = args.get('max_size', 9)
    variable_size = args.get('variable_size', True)
    if variable_size:
        size = random.randint(1, max_size)
    else:
        size = max_size

    indices = random.sample(range(len(representation)), size)
    values = random.uniform(next(bounder.lower_bound), next(bounder.upper_bound), len(indices))
    return OrderedDict({i: v for i, v in zip(indices, values)})