<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def random_codebuch(path):
 """Generate a month-long codebuch and save it to a file."""


    lines = []
    for i in range(31):
        line = str(i+1) + " "

        # Pick rotors
        all_rotors = ['I', 'II', 'III', 'IV', 'V']
        rotors = [random.choice(all_rotors)]
        while len(rotors) < 3:
            r = random.choice(all_rotors)
            if not r in rotors:
                rotors.append(r)
                line += r + ' '

        # Pick rotor settings.
        settings = [str(random.randint(1, 26))]
        while len(settings) < 3:
            s = str(random.randint(1, 26))
            if not s in settings:
                settings.append(s)
                line += s + ' '

        # Pick plugboard settings.
        plugboard = []
        while len(plugboard) < 20:
            p1 = random_letters(1)
            p2 = random_letters(1)
            if (not p1 == p2 and
               not p1 in plugboard and not p2 in plugboard):
                plugboard.extend([p1, p2])
                line += p1 + p2 + ' '

        # Pick a reflector.
        reflector = random.choice(['B', 'C'])
        line += reflector

        line += os.linesep
        lines.append(line)

    with open(path, 'w') as f:
        f.writelines(lines)

    return lines