python 随机数生成
来源:互联网 发布:c语言从偶数2加到100 编辑:程序博客网 时间:2024/06/05 06:41
import random#随机整数:random.randint(0,99)#21#随机选取0到100间的偶数:random.randrange(0, 101, 2)#42#随机浮点数:random.random() #0.85415370477785668random.uniform(1, 10)#5.4221167969800881#随机字符:random.choice('abcdefg&#%^*f')#'d'#多个字符中选取特定数量的字符:random.sample('abcdefghij',3) #['a', 'd', 'b']#多个字符中选取特定数量的字符组成新字符串:''.join(random.sample(['a','b','c','d','e','f','g','h','i','j'], 3)).replace(" ","")#'fih'#随机选取字符串:random.choice ( ['apple', 'pear', 'peach', 'orange', 'lemon'] )#'lemon'#洗牌:items = [1, 2, 3, 4, 5, 6]random.shuffle(items)items#[3, 2, 5, 6, 4, 1]
refer:参考资料: http://docs.python.org/lib/module-random.html http://blog.chinaunix.net/space.php?uid=20587169&do=blog&cuid=373575
- Python生成随机数
- python 随机数生成
- python随机数生成
- Python生成随机数
- python随机数生成
- python随机数生成
- python 随机数生成
- python中的随机数生成
- Python random 生成随机数
- python生成随机数
- python随机数生成
- Python生成随机数
- python生成随机数
- python随机数生成
- python生成随机数
- Python生成随机数
- python随机数生成
- Python随机数生成方法
- 高频头设置原理
- libpcap编译
- ProGuard
- C#中所有的关键字以及委托例
- lock_sga and pre_page_sga设置
- python 随机数生成
- Mysql 存储过程和函数区别
- Sandboxie 3.56 Final 特别版
- freemaker eclipse 插件下载
- String与字符串池
- linux 哥来了
- 简明Python教程 --- 9.数据结构
- vc6.0中 POP-up Menu不支持此接口的解决方法
- Windows 7开机出现BOOTMGR is compressed,Press Ctrl+Alt+Del to restart的解决方法(用一张带WinPE的Ghost光盘)