Steven D'Aprano added the comment: Your example of int(0.99999999999999995) returning 1 is misleading, because 0.999...95 is already 1.0. (1.0 - 1/2**53) = 0.9999999999999999 is the nearest float distinguishable from 1.0.
It seems to me that either random() may return 1.0 exactly (although I've never seen it) or that 0.9999999999999999*len(s) rounds up to len(s), which I guess is more likely. Sure enough, that first happens with a string of length 2049: py> x = 0.9999999999999999 py> for i in range(1, 1000000): ... if int(i*x) == i: ... print i ... break ... 2049 However your string has length 35, and it certainly doesn't happen there: py> int(x*len(s)) 34 ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24546> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com