""" Version B of the password example: the correct one. Companion to "LLMs Can Write Code, but Cannot Read Your Mind" https://hed.am/briefs/llms-can-write-code-but-cannot-read-your-mind/ python3 password-secrets.py The only difference from password-random.py is the import. `secrets` draws on the operating system's cryptographic randomness (getrandom, /dev/urandom, or the platform equivalent), which is designed so that seeing any amount of previous output gives you no practical way to work out the next value. `secrets.choice` also avoids the modulo bias that a naive `% len(alphabet)` introduces when the alphabet does not divide the generator's range evenly. Neither property is visible from the outside: both files print sixteen scrambled characters, and no test anyone would think to write tells them apart. """ # Version B - looks the same, actually correct import secrets, string ALPHABET = string.ascii_letters + string.digits def password(n: int = 16) -> str: return ''.join(secrets.choice(ALPHABET) for _ in range(n)) print(password())