python(5)–random模块及验证码
1. random.random() 随机小数
>>> random.random()
0.6633889413427193
2. random.randint(1,9) 1-9之间随机生成一位数
>>> random.randint(1,9)
2
>>> random.randint(1,9)
2
>>> random.randint(1,9)
8
>>> random.randint(1,9)
3
3. random.randrange(1,9) 1-9之间随机生成一位数
>>> random.randrange(1, 9)
1
>>> random.randrange(1, 9)
6
验证码:
1. 生成四位数字验证码
import random check_code = '' for i in range(4):
current = random.randint(0, 9)
check_code = "%s%s" % (check_code, str(current)) print(check_code)
2. 生成六位数字字母的验证码
import random check_code = '' for i in range(6):
current = random.randint(0, 4)
if current != i:
tmp = str(chr(random.randint(65, 90))) #65-90是字母的ASCII码
else:
tmp = str(random.randint(0, 9))
check_code = "%s%s" % (check_code, tmp)
print(check_code)
python(5)–random模块及验证码的更多相关文章
- python的random模块(生成验证码)
python的random模块(生成验证码) random模块常用方法 random.random() #生成0到1之间的随机数,没有参数,float类型 random.randint(1, 3) # ...
- 【转】python之random模块分析(一)
[转]python之random模块分析(一) random是python产生伪随机数的模块,随机种子默认为系统时钟.下面分析模块中的方法: 1.random.randint(start,stop): ...
- Python中random模块生成随机数详解
Python中random模块生成随机数详解 本文给大家汇总了一下在Python中random模块中最常用的生成随机数的方法,有需要的小伙伴可以参考下 Python中的random模块用于生成随机数. ...
- python random 模块及验证码功能
random模块 import random random.random() random.randint(1,3) # 1-3的整数包括3 import random print(random.ra ...
- python-Day5-深入正则表达式--冒泡排序-时间复杂度 --常用模块学习:自定义模块--random模块:随机验证码--time & datetime模块
正则表达式 语法: mport re #导入模块名 p = re.compile("^[0-9]") #生成要匹配的正则对象 , ^代表从开头匹配,[0 ...
- 你真的用好了Python的random模块吗?
random模块 用于生成伪随机数 源码位置: Lib/random.py(看看就好,千万别随便修改) 真正意义上的随机数(或者随机事件)在某次产生过程中是按照实验过程中表现的分布概率随机产生的,其结 ...
- python 之 random 模块、 shutil 模块、shelve模块、 xml模块
6.12 random 模块 print(random.random()) (0,1)----float 大于0且小于1之间的小数 print(random.randint(1,3)) [1,3] 大 ...
- Python time & random模块
time模块 三种时间表示 在Python中,通常有这几种方式来表示时间: 时间戳(timestamp) : 通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的 ...
- Python之random模块
random模块 产生随机数的模块 是Python的标准模块,直接导入即可 import random 1)随机取一个整数,使用.randint()方法: import random print(ra ...
随机推荐
- RabbitMQ (三) 发布/订阅 -摘自网络
这篇博客中,我们会做一些改变,就是把一个消息发给多个消费者,这种模式称之为发布/订阅(类似观察者模式). 为了验证这种模式,我们准备构建一个简单的日志系统.这个系统包含两类程序,一类程序发动日志,另一 ...
- Hibernate之继承映射
1. Hibernate支持三种继承映射策略: –使用 subclass进行映射:将域模型中的每一个实体对象映射到一个独立的表中,也就是说不用在关系数据模型中考虑域模型中的继承关系和多态. –使用 j ...
- POJ 2185 Milking Grid(KMP)
Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4738 Accepted: 1978 Desc ...
- codeforces 630B Moore's Law
B. Moore's Law time limit per test 0.5 seconds memory limit per test 64 megabytes input standard inp ...
- MVC4学习过程记录
终于决定开始尝试Web开发,即是为了工作也是为了自己的兴趣,决定还是从MS的MVC4开始. 首先从Asp.Net MVC4入门指南这个系列开始学习(http://www.cnblogs.com/pow ...
- Spring JdbcTemplate小结
提供了JdbcTemplate 来封装数据库jdbc操作细节: 包括: 数据库连接[打开/关闭] ,异常转义 ,SQL执行 ,查询结果的转换 使用模板方式封装 jdbc数据库操作-固定流程的动作,提供 ...
- 推荐一个CodeProject上的SlideForm控件
CodeProject有一篇文章介绍了怎么实现一个SlideForm,非常不错,收藏在此. http://www.codeproject.com/KB/dialog/csslideform.aspx ...
- 利用procdump+Mimikatz 绕过杀软获取Windows明文密码(转)
Mimikatz现在已经内置在Metasploit’s meterpreter里面,我们可以通过meterpreter下载.但是你如果觉得还要考虑杀毒软件,绑定payload之类的东西太过复杂,我们可 ...
- CDOJ 481 Apparent Magnitude 水题
Apparent Magnitude Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/sh ...
- delphi 插入表格HTML代码
<table width="174" height="76" border="1" align="center" ...