summaryrefslogtreecommitdiffstats
path: root/Modules/_randommodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r--Modules/_randommodule.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 51c0842..64e44e3 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -474,12 +474,15 @@ _random_Random_getrandbits_impl(RandomObject *self, int k)
uint32_t *wordarray;
PyObject *result;
- if (k <= 0) {
+ if (k < 0) {
PyErr_SetString(PyExc_ValueError,
- "number of bits must be greater than zero");
+ "number of bits must be non-negative");
return NULL;
}
+ if (k == 0)
+ return PyLong_FromLong(0);
+
if (k <= 32) /* Fast path */
return PyLong_FromUnsignedLong(genrand_uint32(self) >> (32 - k));