Simple random number generators
Project description
- Contact:
- http://craig.mcqueen.id.au/
- Copyright:
- 2010 Craig McQueen
Simple pseudo-random number generators, from George Marsaglia.
Intro
The simplerandom package is provided, which contains modules containing classes for various simple pseudo-random number generators.
The algorithms were obtained from a newsgroup post by George Marsaglia [1]. The algorithms were specified in C in the newsgroup post. For the purpose of prototyping software in a high-level language such as Python, before writing it in faster C, it is useful to have identical algorithms implemented in both Python and C.
One module provides Python iterators, which generate simple unsigned 32-bit integers identical to their C counterparts.
Another module provides random classes that are sub-classed from the class Random in the random module of the standard Python library.
References
Modules Provided
Module |
Description |
---|---|
simplerandom.iterators |
Iterator classes, which generate unsigned 32-bit integers. |
simplerandom.random |
Classes that conform to standard Python random.Random API. |
Random Number Generators Provided
In simplerandom.iterators, the following pseudo-random number generators are provided:
Generator |
Notes |
---|---|
RandomCongIterator |
|
RandomSHR3Iterator |
|
RandomMWCIterator |
|
RandomKISSIterator |
Combination of MWC, Cong and SHR3 |
RandomLFIB4Iterator |
|
RandomSWBIterator |
|
_RandomFibIterator |
Not useful on its own, but can be used in a combination with other generators. |
In simplerandom.random, the following pseudo-random number generators are provided:
Generator |
Notes |
---|---|
RandomCong |
|
RandomSHR3 |
|
RandomMWC |
|
RandomKISS |
Combination of MWC, Cong and SHR3 |
RandomLFIB4 |
|
RandomSWB |
Usage
Iterators
>>> import simplerandom.iterators as sri >>> rng = sri.RandomKISSIterator(123958, 34987243, 3495825239, 2398172431) >>> next(rng) 21111917L >>> next(rng) 1327965872L >>> next(rng) 2128842716L
Random class API
>>> import simplerandom.random as srr >>> rng = srr.RandomKISS(258725234) >>> rng.random() 0.30631872435766117 >>> rng.random() 0.43903576112750442 >>> rng.random() 0.69756297733927486
Supported Python Versions
Currently this has had basic testing on Ubuntu 10.04 32-bit and Windows XP 32-bit. It passes the basic simplerandom.iterators.test unit tests, as well as basic manual testing of simplerandom.random. A more thorough unit test suite is needed.
In Ubuntu, it has been tested on Python 2.6 and 3.1 and passes.
In Windows, it has been tested on Python 2.4, 2.5, 2.6, 2.7 and 3.1. It passes under these versions.
The pure Python code is expected to work on 64-bit platforms, but has not been tested. The Cython version of simplerandom.iterators should work on 64-bit platforms, but has not been tested.
Installation
The simplerandom package is installed using distutils. If you have the tools installed to build a Python extension module, run the following command:
python setup.py install
If you cannot build the C extension, you may install just the pure Python implementation, using the following command:
python setup.py build_py install --skip-build
Unit Testing
Basic unit testing of the iterators is in simplerandom.iterators.test. It duplicates the tests of the C algorithms given in the original newsgroup post [1]. It should print seven lines, all containing 0.
To run it on Python >=2.5:
python -m simplerandom.iterators.test
Alternatively, in the test directory run:
python test_iterators.py
A more thorough unit test suite is needed.
License
The code is released under the MIT license. See LICENSE.txt for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for simplerandom-0.7.1.win32-py3.2.msi
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9457c816bc5d2af17bc71527ed322221f87987fa13277e93dbdfc9da974c9ee3 |
|
MD5 | 69d6082bb5e1c7c48be5b327503880e3 |
|
BLAKE2b-256 | 0cafd29974e1d555c87765497f1846c00c04574b0c3d2af97b461c3b741275a2 |
Hashes for simplerandom-0.7.1.win32-py3.1.msi
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69cc7c292f6f3d9568d469abf0b3996bb9b0dbab38d8c95d5aaaf4ac6c591217 |
|
MD5 | d712f80b94376bac093175fc1dac1438 |
|
BLAKE2b-256 | 7d20b9b8c429ebb4b26b515a01f34a765815835e0aa4b5bf1646ed39f7e4ba1d |
Hashes for simplerandom-0.7.1.win32-py2.7.msi
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e76246d8fb788e17af7716ce34493488eb599256f0971626c85b5f6caa52c54 |
|
MD5 | 369d9a88894b50d7521d4490a6ce51b0 |
|
BLAKE2b-256 | fe23851b3ba1320e105b572aa5cbc95a023245d520d5a61b78a94599b287a5ff |
Hashes for simplerandom-0.7.1.win32-py2.6.msi
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ee8fcb0bfaea3fa30e984344c7ebb0fde76d155122280870de32c5a0ae90944 |
|
MD5 | ce3356a99a3a1a940b1f57bdc736d659 |
|
BLAKE2b-256 | e82ae94059f7a76b461177f94f3ed9e7ffd8e3b9c42ade25b3934aade317c44c |
Hashes for simplerandom-0.7.1.win32-py2.5.msi
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69cfb187d3572d0a888bfb82b0672fa3e341017a7cb39a4aed7f31436bc7c050 |
|
MD5 | 74d4a290e571a512357eb68a569b10ee |
|
BLAKE2b-256 | 8a79c691930988b81b281816a0f0af5aa541498494e35306215ace6199faca9c |