Skip to main content

Python version of the Mersenne Twister 64-bit pseudorandom number generator

Project description

PyMT64

PyMT64 is a Python version of the Mersenne Twister (MT) 64-bit pseudorandom number generator by Takuji Nishimura and Makoto Matsumoto (see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html and the references below).

This customised version is thread safe and was interfaced from C to Python (see pymt64.c)

This module provides the following methods:
- init : initialisation of the state vector (mt) used by the pseudorandom number generator (PNG)
- uniform : generation of an uniform distribution
- normal : generation of two Normal distributions
- poisson : generation of a Poisson distribution

The period of the PNG is 2**19937-1.

Example:
import time
import pymt64
seed = int(time.time()) # the initial seed
mt = pymt64.init(seed) # initialisation of the state vector used by the PNG
u = pymt64.uniform(mt,10) # generation of an uniform distribution
print u
[ 0.94295421 0.47222327 0.634552 0.26012686 0.38431784 0.23995444
0.02175826 0.8209848 0.79266556 0.8638286 ]

For a complete example, see pymt64_test.py

Note: the state vector 'mt' returned by pymt64.init has 313 elements instead of the 312 elements of the original C code. This is because the 313th element store the associated counter (mti).

R. Samadi (LESIA, Observatoire de Paris), 22 Dec. 2012

References:
T. Nishimura, ``Tables of 64-bit Mersenne Twisters''
ACM Transactions on Modeling and
Computer Simulation 10. (2000) 348--357.
M. Matsumoto and T. Nishimura,
``Mersenne Twister: a 623-dimensionally equidistributed
uniform pseudorandom number generator''
ACM Transactions on Modeling and
Computer Simulation 8. (Jan. 1998) 3--30.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyMT64-1.0.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file PyMT64-1.0.tar.gz.

File metadata

  • Download URL: PyMT64-1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyMT64-1.0.tar.gz
Algorithm Hash digest
SHA256 01af1eddc4a49b1e9f8b36c2bae5dda48946b6d611663c8dd3bfbda87f836640
MD5 7810d0b780df1e7784bddccaabfc78c5
BLAKE2b-256 d2c800698d1f565cbb14baf9c4b35418cbca5de7ed2019ff749c31796ed6442d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page