Python: why does `random.randint(a, b)` return a range inclusive of `b`?

后端 未结 4 1616
再見小時候
再見小時候 2020-12-05 04:06

It has always seemed strange to me that random.randint(a, b) would return an integer in the range [a, b], instead of [a, b-1] like

4条回答
  •  醉酒成梦
    2020-12-05 04:30

    This is speculation, but normal human usage of 'give me a random number from a to b' is inclusive. Implementing it that way sort of makes sense, given Python's general philosophy of being a more human-readable language.

提交回复
热议问题