您的位置 首页 编程资料

Python3:生成6位随机字符串,字符可以是数字、大写字母、小写字母

import random

"""
@file: 生成随机字符.py
@time: 2019年8月13日14:21:41
"""
randomStr = ""

for i in range(6):
    temp = random.randrange(0, 3)
    if temp == 0:
        ch = chr(random.randrange(ord('A'), ord('Z') + 1))
        randomStr += ch
    elif temp == 1:
        ch = chr(random.randrange(ord('a'), ord('z') + 1))
        randomStr += ch
    else:
        ch = str((random.randrange(0, 10)))
        randomStr += ch

print(randomStr)

 您阅读这篇文章共花了:

关于作者: YJ大表哥

热门文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注