从函数签名中我们可以知道:In [7]: random.randrange?
Signature: random.randrange(start, stop=None, step=1, _int=, _maxwidth=9007199254740992L)
Docstring:
Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the
endpoint; in Python this is usually not what you want.
File: /usr/lib/python2.7/random.py
Type: instancemethod
In [8]: random.uniform?
Signature: random.uniform(a, b)
Docstring: Get a random number in the range [a, b) or [a, b] depending on rounding.
File: /usr/lib/python2.7/random.py
Type: instancemethod
randrange 是从 range(start, stop[, step]) 随机挑选一个,生成的一定是 int ;
uniform 是从 [a, b) 或 [a, b] 中生成一个随机数,生成的是 float;
这两个使用场景不一样。
【相关推荐】
1.特别推荐:“php程序员工具箱”V0.1版本下载
2. Python免费视频教程
3. Python基础之uniform()的详解