I was exploring the random module and can't find a correct answer to whether b is inclusive or exclusive in random.uniform(a, b).
In a code like random.uniform(0, 1), some answers say 1 is included while others say 1 is never produced. What's the correct answer?
The documentation for random.uniform(a, b) suggests that you may encounter cases where the upper limit b is included in the range due to how floating-point numbers are represented, but it's not guaranteed:
Return a random floating point number N such that
a <= N <= bfora <= bandb <= N <= aforb < a.The end-point value
bmay or may not be included in the range depending on floating-point rounding in the equationa + (b-a) * random().
So sometimes the upper limit b may be included, and sometimes it may not be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With