More than 1 year has passed since last update.

commons-lang(Java)のRandomStringUtils.randomAlphabetic(n)相当の処理。調べれば出てくるが備忘録として。

random_string
import string
import random

n = 5
# ユーティリティ関数にすると便利かも?
random_str = ''.join([random.choice(string.ascii_letters + string.digits) for i in range(n)])
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.