diff -r 9347869d1066 Modules/_randommodule.c --- a/Modules/_randommodule.c Thu Dec 13 19:09:33 2012 +0200 +++ b/Modules/_randommodule.c Thu Dec 13 22:46:40 2012 +0200 @@ -389,6 +389,9 @@ return NULL; } + if (k <= 32) /* Fast path */ + return PyLong_FromUnsignedLong(genrand_int32(self) >> (32 - k)); + bytes = ((k - 1) / 32 + 1) * 4; bytearray = (unsigned char *)PyMem_Malloc(bytes); if (bytearray == NULL) {