is it possible to find random floats in range [a,b] in python?

后端 未结 5 2120
旧巷少年郎
旧巷少年郎 2021-01-06 17:07

I\'m trying to generate in python random floats in the range of [0.8,0.9] , but unfortanetly all the tools i found could only generate randoms in the range of [a,b) for floa

5条回答
  •  温柔的废话
    2021-01-06 17:20

    The probability of generating exactly an endpoint value should be negligible. What bad consequences do you worry about if you just use Random.uniform(0.8,0.9)? (And are you also worried about the fact that the double-precision floats you get when you say "0.8" and "0.9" aren't in fact exactly 8/10 and 9/10?)

    It's possible that you have very unusual requirements; but for, say, 99.9% of applications I think the answer is: just use Random.uniform(a,b) and don't worry about it.

提交回复
热议问题