random number generation: the newbie asks for advice
Neel Krishnaswami
neelk at brick.cswv.com
Wed Dec 29 18:13:37 EST 1999
Alex Martelli <Alex.Martelli at think3.com> wrote:
>
>Is there a decent, Python-interfaced, C-written, stand-alone random
>number generator, with persistable/de-persistable state? Or am I
>being too suspicious of ranlibmodule's quality and should just try to
>yank it out of "Numeric" for a smaller set of dependencies...?
>
>Advice is welcome!
Sounds like you want the Mersenne Twister! From the webpage:
Mersenne Twister(MT) is a pseudorandom number generator developped
by Makoto Matsumoto and Takuji Nishimura (alphabetical order) during
1996-1997. MT has the following merits:
* It is designed with consideration on the flaws of various
existing generators.
* The algorithm is coded into a C source downloadable below.
* Far longer period and far higher order of equidistribution than
any other implemented generators. (It is proved that the period
is 2^19937-1, and 623-dimensional equidistribution property is
assured.)
* Fast generation. (Although it depends on the system, it is
reported that MT is sometimes faster than the standard ANSI-C
library in a system with pipeline and cache memory.)
* Efficient use of the memory. (The implemented C-code mt19937.c
consumes only 624 words of working area.)
The C source is available at:
http://www.math.keio.ac.jp/~matumoto/emt.html
Unfortunately, I don't think it has a Python wrapper yet. It should be
easy to implement, though, since there's only a pair of very small C
functions to wrap.
Neel
More information about the Python-list
mailing list