[issue40286] Add randbytes() method to random.Random

2020-05-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset f01d1be97d740ea0369379ca305646a26694236e by Raymond Hettinger in branch 'master': bpo-40286: Put methods in correct sections. Add security notice to use secrets for session tokens. (GH-19870)

[issue40286] Add randbytes() method to random.Random

2020-05-02 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +19183 pull_request: https://github.com/python/cpython/pull/19870 ___ Python tracker ___

[issue40286] Add randbytes() method to random.Random

2020-04-29 Thread STINNER Victor
STINNER Victor added the comment: It removed the C implementation of randbytes(): it was the root issue which started discussions here and in bpo-40346. I rejected bpo-40346 (BaseRandom) and related PRs. I close the issue. -- stage: patch review -> resolved status: open -> closed

[issue40286] Add randbytes() method to random.Random

2020-04-29 Thread STINNER Victor
STINNER Victor added the comment: New changeset 2d8757758d0d75882fef0fe0e3c74c4756b3e81e by Victor Stinner in branch 'master': bpo-40286: Remove C implementation of Random.randbytes() (GH-19797) https://github.com/python/cpython/commit/2d8757758d0d75882fef0fe0e3c74c4756b3e81e --

[issue40286] Add randbytes() method to random.Random

2020-04-29 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +19118 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/19797 ___ Python tracker ___

[issue40286] Add randbytes() method to random.Random

2020-04-24 Thread STINNER Victor
STINNER Victor added the comment: Raymond: > The randbytes() method needs to depend on genrandbits(). I created PR 19700 which allows to keep the optimization (C implementation in _randommodule.c) and Random subclasses implement randbytes() with getrandbits(). --

[issue40286] Add randbytes() method to random.Random

2020-04-21 Thread STINNER Victor
STINNER Victor added the comment: Raymond: > Also, I don't want randbytes() in the C extension. We're tried to keep as > much of the code as possible in pure Python and only have the MersenneTwister > specific code in the C module. The improves maintainability and makes the > code more

[issue40286] Add randbytes() method to random.Random

2020-04-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: $ ./python -m timeit -s 'import random' 'random.randbytes(10**6)' 200 loops, best of 5: 1.36 msec per loop $ ./python -m timeit -s 'import random' 'random.getrandbits(10**6*8).to_bytes(10**6, "little")' 50 loops, best of 5: 6.31 msec per loop The Python

[issue40286] Add randbytes() method to random.Random

2020-04-20 Thread STINNER Victor
STINNER Victor added the comment: I created bpo-40346: "Redesign random.Random class inheritance". -- ___ Python tracker ___ ___

[issue40286] Add randbytes() method to random.Random

2020-04-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: When a new method gets added to a module, it should happen in a way that is in harmony with the module's design. -- nosy: +tim.peters ___ Python tracker

[issue40286] Add randbytes() method to random.Random

2020-04-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Direct link to MT code that I would like to leave mostly unmodified: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c -- ___ Python tracker

[issue40286] Add randbytes() method to random.Random

2020-04-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: The randbytes() method needs to depend on genrandbits(). It is documented that custom generators can supply there own random() and genrandbits() methods and expect that the other downstream generators all follow. See the attached example which

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread STINNER Victor
STINNER Victor added the comment: New changeset 87502ddd710eb1f030b8ff5a60b05becea3f474f by Victor Stinner in branch 'master': bpo-40286: Use random.randbytes() in tests (GH-19575) https://github.com/python/cpython/commit/87502ddd710eb1f030b8ff5a60b05becea3f474f --

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 223221b290db00ca1042c77103efcbc072f29c90 by Serhiy Storchaka in branch 'master': bpo-40286: Makes simpler the relation between randbytes() and getrandbits() (GH-19574)

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +18915 pull_request: https://github.com/python/cpython/pull/19575 ___ Python tracker ___

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- pull_requests: +18914 pull_request: https://github.com/python/cpython/pull/19574 ___ Python tracker ___

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread STINNER Victor
STINNER Victor added the comment: New changeset 9f5fe7910f4a1bf5a425837d4915e332b945eb7b by Victor Stinner in branch 'master': bpo-40286: Add randbytes() method to random.Random (GH-19527) https://github.com/python/cpython/commit/9f5fe7910f4a1bf5a425837d4915e332b945eb7b --

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread STINNER Victor
Change by STINNER Victor : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue40286] Add randbytes() method to random.Random

2020-04-17 Thread STINNER Victor
STINNER Victor added the comment: I wrote a quick benchmark: --- import pyperf import random gen = random.Random() # gen = random.SystemRandom() gen.seed(850779834) if 1: #hasattr(gen, 'randbytes'): func = type(gen).randbytes elif 0: def py_randbytes(gen, n): data =

[issue40286] Add randbytes() method to random.Random

2020-04-15 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: All Random methods give the same result independently of endianess and bitness of the platform. > I don't think that these two implementations give the same result on big and > little endian. The second one does. --

[issue40286] Add randbytes() method to random.Random

2020-04-15 Thread STINNER Victor
STINNER Victor added the comment: The performance of the new method is not my first motivation. My first motivation is to avoid consumers of the random to write a wrong implementation which would be biased. It's too easy to write biased functions without notifying. Moreover, it seems like

[issue40286] Add randbytes() method to random.Random

2020-04-15 Thread STINNER Victor
STINNER Victor added the comment: I updated my PR to rename the method to randbytes(). -- title: Add getrandbytes() method to random.Random -> Add randbytes() method to random.Random ___ Python tracker