views:

82

answers:

2

I have Python 3.1.2 and I'm using Windows XP.

Where can I see Python's implementation of the Mersenne Twister? In the Python docs it is stated that the Mersenne Twister was written in C and the Python History and License ( http://docs.python.org/py3k/license.html?highlight=mersenne%20twister ) states that "The _random module includes code based on a download from http://www.math.keio.ac.jp/matumoto/MT2002/emt19937ar.html."

random.py imports _random which apparently has the Mersenne Twister implementation in it. I can't seem to locate _random.

Any thoughts?

+2  A: 

Try here for the current Python 2.x source, or here for the Python 3.1 source (they're almost identical). It's Modules/_randommodule.c in the source distribution.

Mark Dickinson
interesting, should i have _randommodule.c locally or is that all bunched together in some .dll?
B Rivera
No, you probably don't have a local copy: it'll be either compiled into the main executable or part of a .dll. I'm not really sure which, on Windows.
Mark Dickinson
thanks! 15 char
B Rivera
+2  A: 

_random is written in C, not in Python. You can review the source here:

http://svn.python.org/projects/python/branches/release31-maint/Modules/_randommodule.c

Here's an earlier question that has a Python version in one of the answers:

http://stackoverflow.com/questions/2469031/open-source-implementation-of-mersenne-twister-in-python

djc
thanks for the additional info.
B Rivera