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

后端 未结 5 2132
旧巷少年郎
旧巷少年郎 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:27

    If it really matters, then you can do this:

    def uniform_closed(a, b):
         while True:
             r = random.uniform(a, b + (b - a) * 0.01)
             if r <= b: return r
    

提交回复
热议问题