import random, string
print(''.join(random.choices(string.ascii_lowercase, k=20)))
# => 'vruffnprgthivdocbpgk'
Return a k sized list of elements chosen from the population with replacement. If the population is empty, raises IndexError.
with replacement
なので重複がある。
import random, string
print(''.join(random.sample(string.ascii_lowercase, k=20)))
# => 'piwuhekfvrgmaqnxzbcj'
Return a k length list of unique elements chosen from the population sequence or set. Used for random sampling without replacement.
without replacement
なので重複はない。