diff -r d229032dc213 Modules/_randommodule.c --- a/Modules/_randommodule.c Tue Apr 17 22:48:06 2012 -0400 +++ b/Modules/_randommodule.c Thu Apr 19 08:15:29 2012 +0100 @@ -427,8 +427,19 @@ mt[j] = tmp; } - for (i = 0; i < N; i++) + for (i = 0; i < N; i++) { mt[i] += i+1; + mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ + } + + /* Make sure the state is nonzero: in the unlikely event that mt[1] through + mt[N-1] are all zero, we set the MSB of mt[0]. */ + tmp = 0; + for (i = 1; i < N; i++) { + tmp |= mt[i]; + } + if (tmp == 0) + mt[0] = 0x80000000UL; self->index = N; Py_INCREF(Py_None);