python返回随机字符

返回随机的指定长度的数字加字母的字符串

import random

def getRandomSet(bits):
    num_set = [chr(i) for i in range(48,58)]
    char_set = [chr(i) for i in range(97,123)]
    total_set = num_set + char_set
    value_set = "".join(random.sample(total_set, bits))
    return value_set

 

posted @ 2021-02-19 10:46  牛郎  阅读(197)  评论(0编辑  收藏  举报