[Python-Dev] random number generator state

Scott David Daniels Scott.Daniels at Acm.Org
Sat Aug 15 21:54:41 CEST 2009


I find I have a need in randomized testing for a shorter version
of getstate, even if it _is_ slower to restore.  When running
exhaustive tests, a failure report should show the start state
of the generator.  Unfortunately, our current state includes a
625-element array.  I want a state that can be read off a report
and typed in to reproduce the state.  Something a bit like the
initial seed, a count of cycle calls, and a few other things.

So, in addition to .getstate() and  .setstate(...), I'd at
least need to have .get_slow_state() and possibly expand what
.setstate(...) takes.  However, a call to .setstate should
reset the counter or all is for naught.  That means I need to
change the results of .getstate, thus giving me three kinds of
input to .setstate: old, new-short, and new-long.  In trying to
get this to work, I found what might be a bug:
code says
   mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
but probably should be:
   mt[0] |= 0x80000000UL; /* MSB is 1; assuring non-zero initial array */

In checking into that issue, I went to the original Mersenne-Twister
code, and I see the original authors are pursuing a newer generator,
dSFMT.

I now have a dilemma.  Should I continue the work on the original M-T
code (which is now seeming problematic for compatibility) or simply make
a new generator with similar calls using dSFMT and put the new feature
in that where there is no compatibility problem.  Which would be more
useful for the Python community?

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-Dev mailing list