[issue40282] random.getrandbits(0) should succeed

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

[issue40282] random.getrandbits(0) should succeed

2020-04-17 Thread Antoine Pitrou
Antoine Pitrou added the comment: New changeset 75a3378810bab03949ad9f653f78d933bdf3879c by Antoine Pitrou in branch 'master': bpo-40282: Allow random.getrandbits(0) (GH-19539) https://github.com/python/cpython/commit/75a3378810bab03949ad9f653f78d933bdf3879c --

[issue40282] random.getrandbits(0) should succeed

2020-04-15 Thread Antoine Pitrou
Change by Antoine Pitrou : -- keywords: +patch pull_requests: +18887 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/19539 ___ Python tracker __

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread STINNER Victor
STINNER Victor added the comment: I created bpo-40286: Add getrandbytes() method to random.Random. -- ___ Python tracker ___ ___ Py

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread STINNER Victor
STINNER Victor added the comment: > That is feature creep and no user has requested it. Python already provides such function in the secrets module, so I'm not sure if what you mean that "no users has requested it". secrets.token_bytes() exists because there is a need for such function. sec

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
Antoine Pitrou added the comment: I agree I don't *need* it per se. However, I suspect that for non-exports it would be easier than `getrandbits(nbytes * 8).to_bytes(nbytes, 'endian')`. As for `secrets.token_bytes()`, it's not really adequate for regular pseudo-random data generation when y

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: Why not use secrets.token_bytes() or randrange(2**b).to_bytes()? Do you really need an API extension? -- nosy: +tim.peters ___ Python tracker _

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
Change by Antoine Pitrou : -- components: +Library (Lib) ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
Change by Antoine Pitrou : -- stage: -> needs patch ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
Antoine Pitrou added the comment: About a hypothetical getrandbytes(), probably 90% of my uses of getrandbits() have been to generate random bytestrings. -- ___ Python tracker __

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I do not want to open an issue if I know that the idea will be rejected. -- ___ Python tracker ___

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Raymond Hettinger
Raymond Hettinger added the comment: +0 for having getrandbits(0) return 0. Conceptually, it is reasonable. Practically, it is a bit inconvenient because the ValueError may have to be moved upstream to the _randbelow() methods. -1 for getrandbytes(). That is feature creep and no user has

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Mark Dickinson
Mark Dickinson added the comment: This was discussed previously in #37000. I agree that `getrandbits(0)` should succeed. -- ___ Python tracker ___ ___

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Seconded. And I wish to add the getrandbytes() method. -- nosy: +serhiy.storchaka ___ Python tracker ___ _

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
Antoine Pitrou added the comment: I think you know the answer to your question ;-) -- ___ Python tracker ___ ___ Python-bugs-list m

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread STINNER Victor
STINNER Victor added the comment: How random would be the 0 returned by getrandbits(0)? :-) -- nosy: +vstinner ___ Python tracker ___ _

[issue40282] random.getrandbits(0) should succeed

2020-04-14 Thread Antoine Pitrou
New submission from Antoine Pitrou : When creating variable-sized random binary strings with random.getrandbits(), you currently have to special case when the number of bytes is 0, because otherwise getrandbits() raises: ValueError: number of bits must be greater than zero It seems like it