[Numpy-discussion] random and RandomArray

Robert Kern rkern at ucsd.edu
Thu Feb 17 07:45:19 EST 2005

Bruce Southey wrote:
> Hi, 
> The Mersenne Twister is available in Python as: 
> /Python-2.4/Modules/_randommodule.c 
> This file contains the outdated information: 
> "The code in this module was based on a download from: 
>           http://www.math.keio.ac.jp/~matumoto/MT2002/emt19937ar.html" 
> The redirected link is titled: Mersenne Twister with improved initialization 
> http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html 
> A brief look at randlib() suggests that it is written so that different uniform 
> generators could be used. Could randf() be rewritten to have the default 
> (current status) function and a second that just to link to the random module 
> library to use the Mersenne Twister?  
> Okay, I do know it is not that easy (the seed code would also need to change so 
> account for which generator is being used) but may be sufficient. 

All the functions from _randommodule.c that we would need to use are 
declared static. I'm fairly sure this precludes trying to "link" to 
_randommodule.so to use these functions. The standard way to do such a 
thing would be for _randommodule.c to expose function pointers as 
PyCObjects, but that would require modification of _randommodule.c.

The path of least resistence is to just duplicate the code. It's short, 
clean, well-tested, and widely-used. It should not present a real 
maintenance problem. Certainly no more of one trying to share the 
implementation with _randommodule.

Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

More information about the NumPy-Discussion mailing list