Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正如标题所暗示的,希望生成一个介于 0.3 < x < 0.7 之间的随机浮点数。
我目前使用 while 循环来检查随机浮点数是否在该范围内。我想知道是否有更好的方法来做到这一点。
0.3 + random-float 0.4会给你 0.3 <= x < 0.7。
0.3 + random-float 0.4
如果你真的不想要 0.3,我想你总是可以循环出那个。我不确定是否有更好的方法。