使用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中的单引号双引号有什么区别

Python实现的根据文件名查找数据文件功能示例

Python print 按逗号或空格分隔的方法

Python格式化输出是什么意思

Python可以输入中文吗

为什么要设计好目录结构?

Python 定时修改数据库的示例代码_Python

Python抓取网页乱码的原因及解决方法

int是Python的保留字吗

Python中chr什么意思

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




打赏

取消

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

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

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

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

评论

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