I'm trying to generate a random number between 0.1 and 1.0.
We can't use rand.randint
because it returns integers.
We have also tried random.uniform(0.1,1.0)
, but it returns a value >= 0.1 and < 1.0, we can't use this, because our search includes also 1.0.
Does somebody else have an idea for this problem?
How "accurate" do you want your random numbers? If you're happy with, say, 10 decimal digits, you can just round random.uniform(0.1, 1.0)
to 10 digits. That way you will include both 0.1
and 1.0
:
round(random.uniform(0.1, 1.0), 10)
To be precise, 0.1
and 1.0
will have only half of the probability compared to any other number in between and, of course, you lose all random numbers that differ only after 10 digits.