python 随机数与随机字符串

Posted by bower on August 05, 2009
python

http://gsc-research.de/gsc/research/hv_berichte/detailansicht/index.html?tx_mfcgsc_unternehmen[uid]=3223 分享给你的朋友->bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

http://irinakirilenko.com/?deribaska=bin%C3%A4re-optionen-handeln-in-deurschland&00a=6b binäre optionen handeln in deurschland 随机整数:
>>> import random
>>> random.randint(0,99)
21

japan blood group dating 随机选取0到100间的偶数:
>>> import random
>>> random.randrange(0, 101, 2)
42

http://laprovence.sk/familjarnosty/894

http://www.sonbuenos.com/viowety/1985 随机浮点数:
>>> import random
>>> random.random()
0.85415370477785668
>>> random.uniform(1, 10)
5.4221167969800881

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

http://surfscooter.com/?maska=mujer-soltera-busca-wiki&652=aa 多个字符中选取特定数量的字符:
>>> import random
random.sample(‘abcdefghij’,3)
[‘a’, ‘d’, ‘b’]

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

http://aronsonfence.com/?viosele=rencontre-avec-femme-aimant-la-moto&9b9=61 随机选取字符串:
>>> 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

right here 分享到:人人网开心网腾讯微博新浪微博豆瓣分享腾讯空间百度搜藏腾讯书签

分享给你的朋友->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