1 import random  # 调用random模块
2
3 a = random.random() # 随机从0-1之间抽取一个小数
4 print(a)
5
6 a = random.randint(0,100) # 随机从0-100之间抽取一个数字
7 print(a)
8
9 a = random.choice('abcdefg') # 随机从字符串/列表/字典等对象中抽取一个元素(可能会重复)
10 print(a)
11
12 a = random.sample('abcdefg', 3) # 随机从字符串/列表/字典等对象中抽取多个不重复的元素
13 print(a)
14
15 items = [1, 2, 3, 4, 5, 6] # “随机洗牌”,比如打乱列表
16 random.shuffle(items)
17 print(items)

最新文章

  1. WCF学习之旅—TcpTrace工具(二十六)
  2. Tween公式 以及四个参数
  3. C#基础---Attribute(标签) 和 reflect(反射) 应用
  4. 浅入浅出“服务器推送”之一:Comet简介
  5. dedecms调用标签总结(一)
  6. pycharm安装
  7. 24点C++程序实现 编程之美1.16
  8. Start of Something New
  9. 导入 from pdfminer.pdfinterp import process_pdf 错误
  10. 记一次令人发狂的 bug Eclipse 开不开 tomcat 7.0
  11. python下module、package导入
  12. Android定位功能
  13. 异常:必须先将 ContentLength 字节写入请求流,然后再调用 [Begin]
  14. How to setup Eclipse with WinAVR and the Eclipse plugin AVR-eclipse
  15. 【swift-总结】函数
  16. Django__WSGI
  17. 越来越火的"中台"是什么
  18. k-近邻(KNN)算法改进约会网站的配对效果[Python]
  19. s21day08 python笔记
  20. swiper 支持性

热门文章

  1. IPOPT安装
  2. leetcode 13. 罗马数字转整数 及 12. 整数转罗马数字
  3. C#获取http图片
  4. 面试突击17:HashMap除了死循环还有什么问题?
  5. golang中通过递归或通道实现斐波那契数列
  6. GAN入门
  7. Programiz C 语言教程·翻译完成
  8. SpringBoot前后端数组交互
  9. 前端开发Grunt工具的安装使用
  10. 用curl发起https请求