def _random_subset_weighted(seq, m, fitness_values, rng):
    """
    Return m unique elements from seq weighted by fitness_values.

    This differs from random.sample which can return repeated
    elements if seq holds repeated elements.

    Modified version of networkx.generators.random_graphs._random_subset
    """
    targets = set()
    weights = [fitness_values[node] for node in seq]
    while len(targets) < m:
        x = rng.choices(list(seq), weights=weights, k=m-len(targets))
        targets.update(x)
    return list(targets)