python 产生随机数,随机字符串
来源:互联网 发布:益思商科留学 知乎 编辑:程序博客网 时间:2024/05/01 05:52
import random
import string
#随机整数:
print random.randint(1,50)
#随机选取0到100间的偶数:
print random.randrange(0, 101, 2)
#随机浮点数:
print random.random()
print random.uniform(1, 10)
#随机字符:
print random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
#多个字符中选取特定数量的字符:
print random.sample('zyxwvutsrqponmlkjihgfedcba',5)
#多个字符中选取特定数量的字符组成新字符串:
print string.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5)).replace(' ','')
#随机选取字符串:
print random.choice(['剪刀', '石头', '布'])
#打乱排序
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print random.shuffle(items)
import string
#随机整数:
print random.randint(1,50)
#随机选取0到100间的偶数:
print random.randrange(0, 101, 2)
#随机浮点数:
print random.random()
print random.uniform(1, 10)
#随机字符:
print random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()')
#多个字符中选取特定数量的字符:
print random.sample('zyxwvutsrqponmlkjihgfedcba',5)
#多个字符中选取特定数量的字符组成新字符串:
print string.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5)).replace(' ','')
#随机选取字符串:
print random.choice(['剪刀', '石头', '布'])
#打乱排序
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print random.shuffle(items)
- python 产生随机数,随机字符串
- python 产生随机数,随机字符串
- python产生随机数,随机字符串
- python 产生随机数,随机字符串
- python 产生随机字符串
- python产生随机字符串
- Shell产生随机数或随机字符串
- [Python]随机数与随机字符串
- [Python]随机数与随机字符串
- Linux shell:使用AWK产生随机数/随机字符串
- python中实现产生随机的字符串
- 产生随机数 双色球随机号码
- Flex 产生随机数、随机颜色
- 随机产生32位随机数
- 从oracle表中随机取记录,产生随机数和随机字符串
- 从oracle表中随机取记录,产生随机数和随机字符串
- 从oracle表中随机取记录,产生随机数和随机字符串
- 从oracle表中随机取记录,产生随机数和随机字符串
- socket
- Linux下/proc目录简介
- Objective-C-类(static)方法、实例方法、overwrite(覆写)、属性(property)
- CSRF原理、测试方法
- java system.out.printf()的常见使用方法
- python 产生随机数,随机字符串
- ContentProvider,SQLiteOpenHelper,SQLiteDatabase三者之间的区别和联系
- 提取汉字首字母C#代码
- datatable中Global与Action的迭代
- jQuery性能优化的28个建议
- error LNK2019:无法解析的外部符号 __cdecl std::_String_base::_Xran(void) 和_Xlen(void)
- Jenkins hash
- baidu美化之网页标题问题最新美化规定
- linux 复制多行