MemoryGarden's Blog

努力 -----------大能猫

C++博客 首页 新随笔 联系 聚合 管理
  118 Posts :: 11 Stories :: 20 Comments :: 0 Trackbacks
>>> random.random()        # Random float x, 0.0 <= x < 1.0
0.37444887175646646


>>> random.uniform(1, 10) # Random float x, 1.0 <= x < 10.0
1.1800146073117523


>>> random.randint(1, 10) # Integer from 1 to 10, endpoints included
7


>>> random.randrange(0, 101, 2) # Even integer from 0 to 100
26


>>> random.choice('abcdefghij') # Choose a random element
'c'

>>> items = [1, 2, 3, 4, 5, 6, 7]
>>> random.shuffle(items)
>>> items
[7, 3, 2, 5, 6, 4, 1]

>>> random.sample([1, 2, 3, 4, 5], 3) # Choose 3 elements
[4, 1, 5]

posted on 2009-12-20 19:18 memorygarden 阅读(197) 评论(0)  编辑 收藏 引用 所属分类: Python

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理