Copyright © 2000-2002 Per Kraulis, Stockholm Bioinformatics Center, SBC
Note added 2007-08-23: This package is currently not maintained. It has been largely superceded by the 'random' module in the standard Python distribution.
The Python module crng implements random-number generators (RNGs) based on several different algorithms producing uniform deviates in the open interval (0,1), i.e. exclusive of the end-point values 0 and 1. A few continuous and integer-valued non-uniform deviates are also available. Each RNG algorithm is implemented as a separate Python extension type. The RNG types are independent of each other, but have very similar interfaces. The entire module is implemented as one single C source code file.
See the documentation for more details, and for installation instructions. Also see some basic seminar notes on random numbers.
The GNU General Public License (GPL; see the file gpl.txt) applies.
The changes in version 1.2 are (see also here):
The changes in version 1.1 are listed here.
|Version 1.2 (released 23 Oct 2002)|
|File||File size (bytes)||Python version||System||Comment|
|Source code package||crng-1.2.tar.gz||42340||any||UNIX||Source code, documentation, Setup.in, scripts, but not the precompiled module (gzipped).|
|Source code files||crng.c||173607||any||any||The single C source code file.|
|crng_pickle.py||8739||any||any||Performs setup for using the pickle/cPickle modules to save and retrieve crng type instances.|
|validate.py||5814||any||any||Validates the implementation of a few RNG implementations in crng.|
|profile.py||3672||any||any||Performs profiling (CPU timing) of the crng implementation.|
|display.py||6346||any||any||Displays various non-uniform distributions in a 2D plot using Tkinter.|
2.0, 2.1, 2.2(?)
|any||Installation script for Distutils.|
|Setup.in||179||any||UNIX||Setup file for compiling the module under UNIX (old installation system).|
|Documentation||doc.html||59183||any||any||The documentation for the crng module (HTML).|
|Precompiled||crng_21_rh71_i386.so||175558||2.1||Linux Red Hat 7.1, Intel 386||Not gzipped; rename to crng.so for proper operation.|
|crng_21_rh72_i386.so||175458||2.1||Linux Red Hat 7.2, Intel 386||Not gzipped; rename to crng.so for proper operation.|
|crng_21_irix65.so||139012||2.1||SGI IRIX 6.5||Not gzipped; rename to crng.so for proper operation.|
Here is an example of the basic usage:
>>> import crng >>> r=crng.ParkMiller(seed=123) >>> r() 0.000962643418909 >>> r(2) (0.179147941609, 0.939454629989)
And here is an example of using a deviate other than the uniform distribution:
>>> n=crng.NormalDeviate(rng=crng.Ranlux(), stdev=4.0) >>> n(4) (0.960612428619, 6.30989834512, -0.972826635646, -2.09557141754)
There are already several RNGs available for Python, notably the standard module random (implementing various random-number distributions) based on whrandom (the Wichmann-Hill algorithm). These are coded in Python, and hence slow. The purpose of the crng module is to provide efficient implementations coded in C of several modern RNG algorithms. The design allows easy comparison and interchange of the RNGs in Python code.
The crng module contains a C interface that allows other Python extension modules to directly call the C function for each RNG implementation. One may thereby attain execution speeds close to those possible for a direct implementation in C, while retaining the flexibility of the Python interface.
Several recent and reasonably well-tested RNGs are available in the crng module. This author is by no means an expert on the subject, but having read some of the recent literature, I would recommend using MT19937; it appears to combine speed of execution with good results in several standard tests of RNG quality. It has an astronomical period of approximately 4.3*106001.