python产生随机字符串

python产生随机字符串


def GenerateRandomString(len, basechars = []):
     if (basechars == []):
         x = range(ord('a'), ord('z') + 1)
         x.extend(range(ord('A'), ord('Z') + 1))
         x.extend(range(ord('0'), ord('9') + 1))
         basechars = [chr(i) for i in x]
         ret = ''
         for i in range(len):
            ret += random.choice(basechars)
         return ret

你可能感兴趣的:(python产生随机字符串)