The Question :
470 people think this question is useful
randrange(start, stop) only takes integer arguments. So how would I get a random number between two float values?
The Question Comments :
The Answer 1
724 people think this answer is useful
Use random.uniform(a, b):
>>> random.uniform(1.5, 1.9)
The Answer 2
81 people think this answer is useful
random.uniform(a, b) appears to be what your looking for. From the docs:
Return a random floating point number N such that a <= N <= b for a <= b and b <= N <= a for b < a.
The Answer 3
68 people think this answer is useful
if you want generate a random float with N digits to the right of point, you can make this :
the second argument is the number of decimals.
The Answer 4
6 people think this answer is useful
Most commonly, you’d use:
random.uniform(a, b) # range [a, b) or [a, b] depending on floating-point rounding
Python provides other distributions if you need.
If you have
numpy imported already, you can used its equivalent:
import numpy as np
np.random.uniform(a, b) # range [a, b)
Again, if you need another distribution,
numpy provides the same distributions as python, as well as many additional ones.