生成8位随机字符串

Posted on 2015-09-17 10:09  NooBkey  阅读(456)  评论(0编辑  收藏  举报

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
import string
#第一种方法
seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
sa = []
for i in range(8):
sa.append(random.choice(seed))
salt = ''.join(sa)
print salt

#第二种方法
salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
print salt

Copyright © 2024 NooBkey
Powered by .NET 9.0 on Kubernetes