""" Version A of the password example: the insecure 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-random.py `random` is a Mersenne Twister, built for simulation and modelling. It is seeded from the OS at import, so the output does differ between runs, which is what makes this one hard to catch: it looks random, and for a simulation it is random enough. It does not, however, withstand an observer. The generator's state is 624 32-bit words, and about that many consecutive outputs are enough to reconstruct it and predict every value that follows. Compare with password-secrets.py, which differs by one import. """ # Version A - looks fine, absolutely wrong for security import random, string ALPHABET = string.ascii_letters + string.digits def password(n: int = 16) -> str: return ''.join(random.choice(ALPHABET) for _ in range(n)) print(password())