使用Python进行手机号和数字的随机生成方法


当前第2页 返回上一页

1

2

3

4

5

>>> import random

>>> random.random()

0.7379992978183179

>>> random.random()

0.4720995823183177

(4)sample:数据源是range(30,60,3),从30~59之间(步进是3),也就是30、33、36。。。这样的数字中,选择2个,这2个数字不会重复


1

2

3

4

5

6

>>> random.sample(['a','b','c','d','e'],2)

['d', 'b']

>>> random.sample(['a','b','c','d','e'],2)

['a', 'b']

>>> random.sample(['a','b','c','d','e'],2)

['e', 'd']

其他函数:

(5)seed:要返回相同的随机数,可以设置相同的种子


1

2

3

4

5

6

>>> random.seed(5)

>>> random.random()

0.6229016948897019

>>> random.seed(5)

>>> random.random()

0.6229016948897019

(6)shuffle:随机排列


1

2

3

4

5

6

>>> t=[0,1,2,3,4,5,6]

>>> t

[0, 1, 2, 3, 4, 5, 6]

>>> random.shuffle(t)

>>> t

[5, 4, 2, 0, 6, 1, 3]

以上就是使用Python进行手机号和数字的随机生成方法的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python中encoding是什么意思

Python操作文件方法

Python字符编码讲解

Python爬虫怎么设置请求头

Python类怎么定义全局变量

怎么在ubuntu安装Python

Python的编写规范和命名规范的总结

如何用Python整理附件

Python如何使用unittest测试接口_Python

Python怎么读csv文件

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...