weixin_39574287
weixin_39574287
2021-01-07 13:12

random.randrange and random.randint mishandle large ints

When a number larger than 2^31 - 1 is passed as the upper limit to random.randrange or random.randint, (with 0 as the lower limit, both implicitly and explicitly), those functions sometimes return a negative number. That's too obvious a "limit" to be coincidental. I've gotten it to consistently fail (more than .1% of the time) by adding just 10,000 to 2^31, but I bet it always breaks past that point and I just haven't let my tests run long enough.

该提问来源于开源项目:skulpt/skulpt

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换