Skip to main content

Next-gen RandomState supporting multiple PRNGs

Project description

Travis Build Status Appveyor Build Status

This is a library and generic interface for alternative random generators in Python and Numpy.

Features

  • Immediate drop in replacement for NumPy’s RandomState

# import numpy.random as rnd
import randomstate as rnd
x = rnd.standard_normal(100)
y = rnd.random_sample(100)
z = rnd.randn(10,10)
  • Default random generator is identical to NumPy’s RandomState (i.e., same seed, same random numbers).

  • Support for random number generators that support independent streams and jumping ahead so that substreams can be generated

  • Faster random number generations, especially for Normals using the Ziggurat method

import randomstate as rnd
w = rnd.standard_normal(10000, method='zig')

Included Pseudo Random Number Generators

This modules includes a number of alternative random number generators in addition to the MT19937 that is included in NumPy. The RNGs include:

Differences from numpy.random.RandomState

New Features

  • standard_normal, normal, randn and multivariate_normal all support an additional method keyword argument which can be bm or zig where bm corresponds to the current method and zig uses the much faster (100%+) ziggurat method.

New Functions

  • random_entropy - Read from the system entropy provider, which is commonly used in cryptographic applications

  • random_uintegers - unsigned integers [0, 2**64-1]

  • jump - Jumps RNGs that support it. jump moves the state a great distance. Only available if supported by the RNG.

  • advance - Advanced the core RNG ‘as-if’ a number of draws were made, without actually drawing the numbers. Only available if supported by the RNG.

Status

  • Complete drop-in replacement for numpy.random.RandomState. The mt19937 generator is identical to numpy.random.RandomState, and will produce an identical sequence of random numbers for a given seed.

  • Builds and passes all tests on:

  • Linux 32/64 bit, Python 2.6, 2.7, 3.3, 3.4, 3.5

  • PC-BSD (FreeBSD) 64-bit, Python 2.7

  • OSX 64-bit, Python 2.7

  • Windows 32/64 bit (only tested on Python 2.7 and 3.5, but should work on 3.3/3.4)

Version

The version matched the latest version of NumPy where randomstate.prng.mt19937 passes all NumPy test.

Documentation

An occasionally updated build of the documentation is available on my github pages.

Plans

This module is essentially complete. There are a few rough edges that need to be smoothed.

  • Stream support for MLFG

  • Creation of additional streams from a RandomState where supported (i.e. a next_stream() method)

Requirements

Building requires:

  • Numpy (1.9, 1.10)

  • Cython (0.22, 0.23)

  • Python (2.6, 2.7, 3.3, 3.4, 3.5)

Note: it might work with other versions but only tested with these versions.

All development has been on 64-bit Linux, and it is regularly tested on Travis-CI. The library is occasionally tested on Linux 32-bit, OSX 10.10, PC-BSD 10.2 (should also work on Free BSD) and Windows (Python 2.7/3.5, both 32 and 64-bit).

Basic tests are in place for all RNGs. The MT19937 is tested against NumPy’s implementation for identical results. It also passes NumPy’s test suite.

Installing

python setup.py install

SSE2

dSFTM makes use of SSE2 by default. If you have a very old computer or are building on non-x86, you can install using:

python setup.py install --no-sse2

Windows

Either use a binary installer or if building from scratch using Python 3.5 and the free Visual Studio 2015 Community Edition. It can also be build using Microsoft Visual C++ Compiler for Python 2.7 and Python 2.7, although some modifications are needed to distutils to find the compiler.

Using

The separate generators are importable from randomstate.prng.

import randomstate
rs = randomstate.prng.xorshift128.RandomState()
rs.random_sample(100)

rs = randomstate.prng.pcg64.RandomState()
rs.random_sample(100)

# Identical to NumPy
rs = randomstate.prng.mt19937.RandomState()
rs.random_sample(100)

Like NumPy, randomstate also exposes a single instance of the mt19937 generator directly at the module level so that commands like

import randomstate
randomstate.standard_normal()
randomstate.exponential(1.0, 1.0, size=10)

will work.

License

Standard NCSA, plus sub licenses for components.

Performance

Performance is promising, and even the mt19937 seems to be faster than NumPy’s mt19937.

Speed-up relative to NumPy (Box-Muller)
************************************************************
randomstate.prng-dsfmt-standard_normal             70.5%
randomstate.prng-mlfg_1279_861-standard_normal     26.9%
randomstate.prng-mrg32k3a-standard_normal         -18.7%
randomstate.prng-mt19937-standard_normal           13.5%
randomstate.prng-pcg32-standard_normal             26.1%
randomstate.prng-pcg64-standard_normal             26.2%
randomstate.prng-xorshift1024-standard_normal      27.2%
randomstate.prng-xorshift128-standard_normal       30.0%

Speed-up relative to NumPy (Ziggurat)
************************************************************
randomstate.prng-dsfmt-standard_normal            316.1%
randomstate.prng-mlfg_1279_861-standard_normal    247.0%
randomstate.prng-mrg32k3a-standard_normal          51.2%
randomstate.prng-mt19937-standard_normal          175.9%
randomstate.prng-pcg32-standard_normal            255.9%
randomstate.prng-pcg64-standard_normal            329.1%
randomstate.prng-xorshift1024-standard_normal     362.0%
randomstate.prng-xorshift128-standard_normal      513.7%

Project details


Download files

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

Source Distributions

randomstate-1.11.0.zip (2.8 MB view details)

Uploaded Source

randomstate-1.11.0.tar.gz (2.6 MB view details)

Uploaded Source

randomstate-1.11.0.tar.bz2 (2.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

randomstate-1.11.0-cp35-none-win32.whl (4.6 MB view details)

Uploaded CPython 3.5Windows x86

randomstate-1.11.0-cp35-cp35m-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.5mWindows x86-64

randomstate-1.11.0-cp35-cp35m-macosx_10_5_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.5mmacOS 10.5+ x86-64

randomstate-1.11.0-cp27-none-macosx_10_5_x86_64.whl (5.5 MB view details)

Uploaded CPython 2.7macOS 10.5+ x86-64

randomstate-1.11.0-cp27-cp27m-win_amd64.whl (4.8 MB view details)

Uploaded CPython 2.7mWindows x86-64

randomstate-1.11.0-cp27-cp27m-win32.whl (4.6 MB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file randomstate-1.11.0.zip.

File metadata

  • Download URL: randomstate-1.11.0.zip
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randomstate-1.11.0.zip
Algorithm Hash digest
SHA256 6dfe4395922d24c7b34d39dce20c4f17a83fbfa0c2fc8dbaabd6a545523d63f9
MD5 17f5c813587b6f3eac48eabd7615b8cf
BLAKE2b-256 aff27ff42e8b22780fc27b03acee0a46b664bb43c4591f32567b29aefad6d673

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0.tar.gz.

File metadata

  • Download URL: randomstate-1.11.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randomstate-1.11.0.tar.gz
Algorithm Hash digest
SHA256 a97faf4e2c162dc303bd3a9aa33c3a5c11c8fe3c72d77404fb73bffbb180a031
MD5 57591e18619ad460b82e27a016486c78
BLAKE2b-256 8972ded16051309d4c8d32675524b5dea6f2a9de1777c71bfd2582de46492c06

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0.tar.bz2.

File metadata

  • Download URL: randomstate-1.11.0.tar.bz2
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randomstate-1.11.0.tar.bz2
Algorithm Hash digest
SHA256 ddedcf2ea5e8386b1e3dcb149482058cdeb625d8083f78f49b86ed3223510f1f
MD5 699a4a9630e9ca43e9c2ad653cdbbd4d
BLAKE2b-256 c510bbd76ef8ca758739acf52588b5d4c6e477447cd6e9c24ab3c629fbf0b285

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp35-none-win32.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp35-none-win32.whl
Algorithm Hash digest
SHA256 990e6cb0620bed51abc5eb4df65a358707c9669e66ad0f97df123b7f1bea7dd4
MD5 997c566e4d24b0d9f656f4ebec186713
BLAKE2b-256 0368811984e98aab382a613ab218507b8da778fbd9c94bcf254e22356b6fc1b4

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 32b1e3db95168115d34809656f0084310da12a8828e0b04983902f32f617b423
MD5 cda1de09acb532462287ab5fa406fca5
BLAKE2b-256 53a9229439b511a7d5f13ad810dbb3cfc97286e0ef54e2cf10484b1688537370

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp35-cp35m-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp35-cp35m-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 66333b71f3c706301ff96a597cebd428244be058786815e97892a4e48730da9d
MD5 84ed3c50825964d71198562dd5865486
BLAKE2b-256 200867670def2dfe73974c9c95c36b4acdadc723d7c8765c8d318c61b862324d

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp27-none-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp27-none-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 ae00b7cbe9bf423c1da1f80deaf871d444927453d350192724f068c9bb27b9a2
MD5 df9b99858134def3e45a8f38a7122a0a
BLAKE2b-256 0fbd93eb31c06d92f643e608827a8ee1c75bb1fcd0170396d876dca5ac084b76

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 372dad3c7d4b84dd35aa64da10e5ada43e439e141a047d6a0bbdb2de8f781d2f
MD5 adc7d12d6f2466c955d8515d9055c9ff
BLAKE2b-256 1fbf4d91f3175ac68ecf5769739d2036ba8645675f0cac13e78113f8508fc12c

See more details on using hashes here.

File details

Details for the file randomstate-1.11.0-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for randomstate-1.11.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 61a6611b8712be3232d8781ddd6efbbdc77f10c96e3ca6517b9502ef92641c32
MD5 848b0a06fc3d0dbcab3ce8ab28e043d1
BLAKE2b-256 2e3bd97e2748e64017fbea5ab200fcaa98af6984d38be0a41b28934165bf9a2d

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