python 随机数与随机字符串

Posted by bower on August 05, 2009
python

site 分享给你的朋友->bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

site de rencontre noumea gratuit 随机整数:
>>> import random
>>> random.randint(0,99)
21

meaning of rencontres 随机选取0到100间的偶数:
>>> import random
>>> random.randrange(0, 101, 2)
42

ashley madison dating service

rencontre sud ouest gratuit 随机浮点数:
>>> import random
>>> random.random()
0.85415370477785668
>>> random.uniform(1, 10)
5.4221167969800881

check my blog 随机字符:
>>> import random
>>> random.choice(‘abcdefg&#%^*f’)
‘d’

agence rencontre femme asiatique 多个字符中选取特定数量的字符:
>>> import random
random.sample(‘abcdefghij’,3)
[‘a’, ‘d’, ‘b’]

rencontre celibataire tours 多个字符中选取特定数量的字符组成新字符串:
>>> import random
>>> import string
>>> string.join(random.sample([‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’], 3)).r
eplace(” “,””)
‘fih’

site rencontre gratuit 2016 随机选取字符串:
>>> import random
>>> random.choice ( [‘apple’, ‘pear’, ‘peach’, ‘orange’, ‘lemon’] )
‘lemon’

洗牌:
>>> import random
>>> items = [1, 2, 3, 4, 5, 6]
>>> random.shuffle(items)
>>> items
[3, 2, 5, 6, 4, 1]

random的函数还有很多,此处不一一列举,
参考资料: http://docs.python.org/lib/module-random.html

good online dating one liners 分享到:人人网开心网腾讯微博新浪微博豆瓣分享腾讯空间百度搜藏腾讯书签

分享给你的朋友->bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word