Python3 & 随机生成指定长度的字符串(包含:数字+字母+

2022-11-10  本文已影响0人  乘风破浪的姐姐

场景:随机生成50个字符串,字符串中包含数字、字母、指定特殊字符

def randomStr(length):
#length为字符串长度
    seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
    randomStr= []
    for i in range(length):
        randomStr.append(random.choice(seed))
    randomStr= ''.join(randomStr)
    return randomStr


if __name__ == "__main__":
    ouidlist = []
    for i in range(1,11):
        salt = randomStr(23)
        ouidlist.append(salt)
    ouidstr = str(ouidlist).replace('[','').replace(']','').replace("'","\"")
    print(ouidstr)

输出结果:
"9ONNCKx81GfMZBxitw0rPlf", "Li6hRsy8X_b4_MaJyJETqXT", "VjjgjwN6vo0If7kXWtHlysH", "FGqjtxNzfZ8MaWd1x7bJtEn", "UrQnxwaomVBv9GkyLR0Mdhj", "hKIhsIngdP0DEMHWpJBbCIU", "DH17JqimRTsEg0IHtrbB8co", "kBZ5NfN2L9m7diZLz51gMmk", "jSMGKWdXLtsGVBobcmRxT15", "D3uFXnj3DVYDmA9y0GEVF4j"

上一篇下一篇

猜你喜欢

热点阅读