import random

# range [a,b)   不包含b

# 获取随机整数
# randrange [a,b) 不包含b
a = random.randrange(0, 101, 5) # Even integer from 0 to 100 inclusive 5 - step
print(a) #
# randint[a, b] 包含b
b = random.randint(0, 1)
print(b) # # 获取0.0 - 1.0之间的随机浮点数
c = random.random() # Random float: 0.0 <= x < 1.0
print(c) # 0.15039929566062382 # 根据设定的浮点数范围,获取随机浮点数
d = random.uniform(2.5, 10.0) # # Random float: 2.5 <= x < 10.0
print(d) # 3.3330140631461425 # 序列用函数
# 从非空序列 seq 返回一个随机元素
li = ['aa', 'bb', 'cc', 'dd', 'ee']
b = random.choice(li)
print(b) # aa # 将序列 x 随机打乱位置 改变的是列表
li = "my name is Melody".split()
print(li) # ['my', 'name', 'is', 'Melody']
random.shuffle(li)
print(li) # ['Melody', 'is', 'my', 'name'] # random.sample(population, k)
# 从指定的序列中,随机的截取指定长度的片断,不作原地修改
li = [2, 3, 4, 6, 7, 9, 0]
b = random.sample(li, 3)
print(b) # [4, 6, 2]
print(li) # 原列表未改变 [2, 3, 4, 6, 7, 9, 0]

最新文章

  1. 0038 Java学习笔记-多线程-传统线程间通信、Condition、阻塞队列、《疯狂Java讲义 第三版》进程间通信示例代码存在的一个问题
  2. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
  3. Jquery——简单的视差滚动效果,兼容PC移动端
  4. (四面体)CCPC网络赛 HDU5839 Special Tetrahedron
  5. &lt;二&gt; ASP.NET AutoPostBack
  6. [C#]生成预定义全颜色表
  7. linux系统下root用户和普通用户的时区不一致
  8. iOS 原生二维码扫描,带扫描框和扫描过程动画
  9. poj2942 Knights of the Round Table,无向图点双联通,二分图判定
  10. Android Studio的使用(十二)怎样打包项目
  11. iptabels 的一些配置
  12. 编程练习------C/C++分别实现字符串与整数的转换
  13. daterangepicker 使用方法以及各种小bug修复
  14. 【重要】ionic和Angular的安装步骤
  15. Tecplot: Legend显示与否
  16. 关于js的面相对象
  17. js验证后台传递的map数据是否为空
  18. 本地用maven搭建SpringMvc+redis集成
  19. mysql row日志格式下 查看binlog sql语句
  20. amcharts categoryAxis

热门文章

  1. SQL中ON和WHERE的区别(转)
  2. 魔方---java
  3. Linux下Netty实现高性能UDP服务(SO_REUSEPORT)
  4. selenium--键盘事件
  5. C# Json解析Json = &quot;{\&quot;EX_RETURN\&quot;:[{\&quot;MATNR\&quot;:\&quot;test\&quot;}] }&quot;;
  6. Quill插入html5的video标签
  7. python [[1,2],[3,4],[5,6]]一行代码展开该列表,得出[1,2,3,4,5,6]
  8. spark的运行模式
  9. mongodb非关系型数据库
  10. Python记录wsgi