less than 1 minute read

Here’s a nice one liner for generating a random string using just digits and upper-case letters:

''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(N))

The use of random.SystemRandom is to make the randomness more cryptographically secure.

Via SO.

Leave a comment