import random


def sample_baselines(bls, seed=None):
    """
    Sample a set of baselines with replacement (to be used to generate a
    bootstrap sample).

    Parameters
    ----------
    bls : list of either tuples or lists of tuples
        Set of unique baselines to be sampled from. If groups of baselines
        (contained in lists) are provided, each group will be treated as a
        single object by the sampler; its members will not be sampled
        separately.

    seed : int, optional
        Random seed to use if randomize=True. If None, no random seed will be
        set. Default: None.

    Returns
    -------
    sampled_bls : list of tuples or lists of tuples
        Bootstrap-sampled set of baselines (will include multiple instances of
        some baselines).
    """
    if seed is not None: random.seed(seed)

    # Sample with replacement; return as many baselines/groups as were input
    return [random.choice(bls) for i in range(len(bls))]