import random


def generate_spans(ents=['X', 'Y'], max_span=5, min_span=0, max_spanl=3, min_spanl=1, min_space=0, max_space=1):
    """Generate a series of entity spans. They are be touching each other but don't overlap."""
    i = 0
    n_spans = random.randint(min_span, max_span)
    spans = []
    for _ in range(n_spans):
        ent = random.choice(ents)
        span_length = random.randint(min_spanl, max_spanl)
        span_gap = random.randint(min_space, max_space)
        span_start = i + span_gap
        span_end = span_start + span_length
        i = span_end
        span = "@".join([ent] + list(map(str, range(span_start, span_end))))
        spans.append(span)
    end = random.randint(min_space, max_space)
    return spans, i + end