We can know from the function signature:
In [7]: random.randrange? Signature: random.randrange(start, stop=None, step=1, _int=<type '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 is randomly selected from range(start, stop[, step]), and the generated one must be int;
uniform is from [a, b) or generate a random number in [a, b], the generated number is float;
these two usage scenarios are different.
[Related recommendations]
1.Special recommendation:"php programmer toolbox" V0.1 version Download
3. Detailed explanation of uniform() based on Python
The above is the detailed content of Tips to distinguish randrange() and uniform() in python. For more information, please follow other related articles on the PHP Chinese website!