要使用Random 模块里的一些随机数方法需要先导入random 模块。
下面是几种常用的随机数方法:
以生成随机8位密码,包括大小写字母,数字为例
pwd = ''.join(random.sample(str1,8)) 生成的密码里面的字符不重复
pwd = ''.join(random.choice(str1) for i in range(8)) 这种方式生成的密码里面会有重复的字符