python使用random库生成n个随机数_Python 使用random模块生成随机数

copycode.gif

1 # coding: utf-8

2 # Team : Quality Management Center

3 # Author:Carson

4 # Date :2019/6/20 17:12

5 # Tool :PyCharm

6

7 import random

8 import string

9

10

11 print(random.random()) # 产生 0 到 1 之间的随机浮点数

12 print(random.randint(1, 10)) # 产生 1 到 10 的一个整数型随机数

13 print(random.uniform(1, 5))    # 产生 1 到 5 之间的随机浮点数,区间可以不是整数

14 print(random.choice('tomorrow'))     # 从序列中随机选取一个元素

15 print(random.choice(['剪刀', '石头', '布'])) # 随机选取字符串

16 print(random.randrange(1, 100, 2))     # 生成从1到100的间隔为2的随机整数

17 print(random.sample('zyxwedcba', 5))     # 多个字符中生成指定数量的随机字符

18 # 从a-zA-Z0-9生成指定数量的随机字符:

19 ran_str = ''.join(random.sample(string.ascii_lette

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值