본문 바로가기

Language/Python

[Python] 랜덤 문자열 생성

반응형


영문 대문자와 숫자로 랜덤 문자열을 생성하는 방법을 알아봅니다.


방법

import random
import string

print(''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)))

References

https://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python

반응형