About random.uniform, docstring says:
Get a random number in the range [a, b) or [a, b] depending on rounding.
But I do not know what does ‘depending on rounding’ exactly mean.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The current documentation for
random.uniform()reads:Floating point arithmetic on computers is limited in precision and rounding errors caused by this imprecision may lead to
bnot being included in the full range of values used for the random value thatuniform()returns.random.random()returns a value between 0.0 (inclusive) and 1.0 (exclusive). There are values foraandbwhere a floating point calculation of the suma + (b-a) * (1.0 - epsilon/2)does not equalb, but will be a minute amount lower thanb, while for other combinations the sum does equal tob.epsilonis the minimum precision of a floating point number on your platform (seesys.float_info), and1.0 - epsilon/2the maximum valuerandom.random()can return.If you are interested in the details of why floating point arithmetic on computers is imprecise, I can recommend the following two articles: