[issue43040] random.py randrange() is very slow if the range is a power of 2.
Raymond Hettinger
report at bugs.python.org
Thu Jan 28 13:32:25 EST 2021
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
> python2's implementation of randrange() that uses random()
> under the hood was noticeably faster than python3's
> randrange() that uses getrandbits() under the hood.
Yes, that was a conscious decision. See https://bugs.python.org/issue9025 . We traded performance in order to gain correctness. As noted in the docs:
"Changed in version 3.2: randrange() is more sophisticated about producing equally distributed values. Formerly it used a style like int(random()*n) which could produce slightly uneven distributions."
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43040>
_______________________________________
More information about the Python-bugs-list
mailing list