random模块

#__author__:Administrator}
#data: 2017/12/1

import random

#print(random.random())#随机产生0到1的随机数
# print(random.randint(1,8))#随机产生1到8的整数随机数,包括8
# print(random.choice('hellow'))#序列随机选择一个
# print(random.choice([1,2,3,4,5,5,6,6]))
#print(random.sample([1,2,3,4,5,5,6,6],2))#从序列中重新选择多个值,后面参数设置几个值
# print(random.randrange(1,3))#不包括3

#print(chr(88))#X数字字母转化
#例子,生成验证码
#方法一
# def v_code():
# code = ''
# for i in range(5):
# if i ==random.randint(0,3):
# add = random.randrange(10)
# else:
# add = chr(random.randrange(65,91))
# code +=str(add )
# print(code)

# v_code()


#方法二
# def v_code():
# code = ''
# for i in range(5):
# add = random.choice([random.randrange(10),chr(random.randrange(65,91))])
#
# code += str(add)
# print(code)
#
# v_code()


posted @ 2017-12-01 17:53  无敌帅帅头  阅读(104)  评论(0编辑  收藏  举报