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

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

作者: 乘风破浪的姐姐 | 来源:发表于2022-11-10 15:50 被阅读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"

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/hlcatdtx.html