在python中的randrange函数和uniform函数的区别是什么
1个回答
展开全部
函数签名说的已经比较清楚了啊:
In [7]: random.randrange?
Signature: random.randrange(start, stop=None, step=1, _int=<type 'int'>, _maxwidth=L)
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;
这两个使用场景完全不一样啊,没有什么相互替代的说法
In [7]: random.randrange?
Signature: random.randrange(start, stop=None, step=1, _int=<type 'int'>, _maxwidth=L)
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;
这两个使用场景完全不一样啊,没有什么相互替代的说法
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询