[New-bugs-announce] [issue40282] random.getrandbits(0) should succeed
Antoine Pitrou
report at bugs.python.org
Tue Apr 14 11:32:35 EDT 2020
New submission from Antoine Pitrou <solipsis at pitrou.net>:
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 wouldn't hurt to simply return 0 in that case.
The actual snippet looks something like:
random.getrandombits(nbytes * 8).to_bytes(nbytes, 'little')
----------
messages: 366392
nosy: mark.dickinson, pitrou, rhettinger, steven.daprano
priority: normal
severity: normal
status: open
title: random.getrandbits(0) should succeed
type: enhancement
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40282>
_______________________________________
More information about the New-bugs-announce
mailing list