是否有可能找到在蟒蛇范围[a,b]随机浮动? [英] is it possible to find random floats in range [a,b] in python?

查看:147
本文介绍了是否有可能找到在蟒蛇范围[a,b]随机浮动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在[0.8,0.9]范围内的python随机浮点数生成,但不幸的是,我发现所有的工具只能在[a,b]范围内为浮点数生成随机数。 (如 Random.uniform(a,b)

同时,我尝试了这样的操作: p>

  uniform(0.8,0.90000000001)

但是那真的很坏

有什么想法?

解决方案

[0.8,0.9]和[0.8,0.9]之间的差异是微乎其微的。考虑到二进制浮点的局限性,我不认为这有什么区别,因为无论如何0.9都不能精确表示。使用[0.8,0.9)。


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 floats. ( like Random.uniform(a,b) )

Meanwhile , I tried doing something like this :

uniform(0.8,0.90000000001)

but thats realy bad

any ideas ?

解决方案

The difference between [0.8, 0.9] and [0.8,0.9) is vanishingly small. Given the limitations of binary floating-point, I don't think there even is a difference, since 0.9 can't be precisely represented anyway. Use [0.8,0.9).

这篇关于是否有可能找到在蟒蛇范围[a,b]随机浮动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆