#!/usr/bin/env python3

import random

def pad_string(input_string, total_length=76):
    """Pad the input string with spaces and dashes to make its length equal to
    total_length."""
    padding_length = total_length - len(input_string) - 1
    return input_string + ' ' + '-' * padding_length

def generate_etude():
    """Generate an 'Etude' by populating a list with padded strings."""
    # Initialize the content list with empty strings
    content = ['' for _ in range(23)]

    # Populate specific indices with padded strings
    content[0] = pad_string("TOP ")
    content[11] = pad_string("MIDDLE ")
    content[22] = pad_string("BOTTOM ")

    # Define lists of ranges for different sections
    sections = [
        list(range(1, 6)),
        list(range(6, 11)),
        list(range(12, 17)),
        list(range(17, 22))
    ]

    # Randomly choose one element from each section
    targets = [random.choice(sublist) for sublist in sections]

    # Shuffle the targets
    random.shuffle(targets)

    # Populate the content with letters corresponding to the shuffled targets
    for counter, target in enumerate(targets):
        content[target] = 'ABCD'[counter] + ". <<-- here"

    # Print the content
    for row in content:
        print(row)

def main():
    """Generate 20 'Etudes'."""
    for _ in range(20):
        generate_etude()

if __name__ == '__main__':
    main()
