[Patches] [ python-Patches-658251 ] Mersenne Twister

noreply@sourceforge.net noreply@sourceforge.net
Tue, 24 Dec 2002 08:45:57 -0800


Patches item #658251, was opened at 2002-12-24 11:45
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=658251&group_id=5470

Category: Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Mersenne Twister

Initial Comment:
Alters random.py to easily accept new core 
generators as a superclass.  Added a new class 
WichmannHill for backwards compatibility and to 
serve as a demo of how implement new generators in 
pure python.

Adds _random.c to implement the MersenneTwister 
generator with a 2**19927-1 period, thread-safety, 
and full 53 random bits for each float.

Added test_random.py for non-statistical tests of 
random.py.  If you have any ideas for moving the 
statistical tests, I would love to hear them.

Everything is ready for review and is situated in the 
sandbox under the twister directory.  It includes a 
makefile, setup.py,  a news item, docs and is ready to 
run directly from the sandbox.

Key design decisions needing review:

* getstate() and setstate() now wrap the same 
functions for the core generator so that new 
generators can easily be slipped into place without 
knowing what is going on in random.py and 
random.py's state format can be changed without 
touching the underlying generator.  This decouples 
the two.

* with the new get/set state format, the VERSION 
number was bumped to two.

* I couldn't find a direct analog for jumpahead(n) and 
that may be a problem with other generators too.  
So, I made a weaker implementation that jumps to a 
state far away from the current one.  This means that 
code for the primary use case will still work, but code 
that relies on jumping exact n steps forward will 
break.

* The old WichmannHill code is kept alive in a 
separate subclass.  whseed is now only available 
through that class and is no longer a module level 
attribute.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=658251&group_id=5470