posts - 195,  comments - 30,  trackbacks - 0

import random

a=random.randint(0,1001)#这个生成的区间是 [0,1001]
a=random.randrange(0,10001)#生成的是区间是[0,1001)

print a



random.randrange([start], stop[, step])

Return a randomly selected element from range(start, stop, step)This is equivalent tochoice(range(start, stop, step)), but doesn’t actually build a range object.

And range(start, stop) returns [start, start+step, ..., stop-1], not [start, start+step, ..., stop]. As for why... zero-based counting rules and range(n) should return n elements, I suppose. Most useful for getting a random index, I suppose.

While randint is documented as:

random.randint(a, b)

Return a random integer N such that a <= N <= bAlias for randrange(a, b+1)

So randint is for when you have the maximum and minimum value for the random number you want.

posted on 2012-11-08 06:56 luis 阅读(281) 评论(0)  编辑 收藏 引用

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


<2011年1月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

友情链接

搜索

  •  

最新评论

阅读排行榜

评论排行榜