Random generator supporting multiple PRNGs
Project description
Random Number Generator using settable Basic RNG interface for future NumPy RandomState evolution.
This is a library and generic interface for alternative random generators in Python and NumPy.
Compatibility Warning
RandomGenerator does not support Box-Muller normal variates and so it not 100% compatible with NumPy (or randomstate). Box-Muller normals are slow to generate and all functions which previously relied on Box-Muller normals now use the faster Ziggurat implementation. If you require backward compatibility, a legacy generator, LegacyGenerator, has been created which can fully reproduce the sequence produced by NumPy.
Features
Replacement for NumPy’s RandomState
# import numpy.random as rnd
from randomgen import RandomGenerator, MT19937
rnd = RandomGenerator(MT19937())
x = rnd.standard_normal(100)
y = rnd.random_sample(100)
z = rnd.randn(10,10)
Default random generator is a fast generator called Xoroshiro128plus
Support for random number generators that support independent streams and jumping ahead so that sub-streams can be generated
Faster random number generation, especially for normal, standard exponential and standard gamma using the Ziggurat method
from randomgen import RandomGenerator
# Use Xoroshiro128
rnd = RandomGenerator()
w = rnd.standard_normal(10000, method='zig')
x = rnd.standard_exponential(10000, method='zig')
y = rnd.standard_gamma(5.5, 10000, method='zig')
Support for 32-bit floating randoms for core generators. Currently supported:
Uniforms (random_sample)
Exponentials (standard_exponential, both Inverse CDF and Ziggurat)
Normals (standard_normal)
Standard Gammas (via standard_gamma)
WARNING: The 32-bit generators are experimental and subject to change.
Note: There are no plans to extend the alternative precision generation to all distributions.
Support for filling existing arrays using out keyword argument. Currently supported in (both 32- and 64-bit outputs)
Uniforms (random_sample)
Exponentials (standard_exponential)
Normals (standard_normal)
Standard Gammas (via standard_gamma)
Included Pseudo Random Number Generators
This module includes a number of alternative random number generators in addition to the MT19937 that is included in NumPy. The RNGs include:
MT19937, the NumPy rng
dSFMT a SSE2-aware version of the MT19937 generator that is especially fast at generating doubles
ThreeFry and Philox from Random123 ## Differences from numpy.random.RandomState
New Features
standard_normal, normal, randn and multivariate_normal all use the much faster (100%+) Ziggurat method.
standard_gamma and gamma both use the much faster Ziggurat method.
standard_exponential exponential both support an additional method keyword argument which can be inv or zig where inv corresponds to the current method using the inverse CDF and zig uses the much faster (100%+) Ziggurat method.
Core random number generators can produce either single precision (np.float32) or double precision (np.float64, the default) using the optional keyword argument dtype
Core random number generators can fill existing arrays using the out keyword argument
Standardizes integer-values random values as int64 for all platforms.
New Functions
random_entropy - Read from the system entropy provider, which is commonly used in cryptographic applications
random_raw - Direct access to the values produced by the underlying PRNG. The range of the values returned depends on the specifics of the PRNG implementation.
random_uintegers - unsigned integers, either 32- ([0, 2**32-1]) or 64-bit ([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 RNG ‘as-if’ a number of draws were made, without actually drawing the numbers. Only available if supported by the RNG.
Status
Builds and passes all tests on:
Linux 32/64 bit, Python 2.7, 3.4, 3.5, 3.6 (probably works on 2.6 and 3.3)
PC-BSD (FreeBSD) 64-bit, Python 2.7
OSX 64-bit, Python 3.6
Windows 32/64 bit (only tested on Python 2.7, 3.5 and 3.6, but should work on 3.3/3.4)
Version
The version matched the latest version of NumPy where RandomGenerator(MT19937()) passes all NumPy test.
Documentation
Plans
This module is essentially complete. There are a few rough edges that need to be smoothed.
Creation of additional streams from where supported (i.e. a next_stream() method)
Requirements
Building requires:
Python (2.7, 3.4, 3.5, 3.6)
NumPy (1.10, 1.11, 1.12, 1.13, 1.14)
Cython (0.26+)
tempita (0.5+), if not provided by Cython
Testing requires pytest (3.0+).
Note: it might work with other versions but only tested with these versions.
Development and Testing
All development has been on 64-bit Linux, and it is regularly tested on Travis-CI (Linux/OSX) and Appveyor (Windows). The library is occasionally tested on Linux 32-bit and Free BSD 11.1.
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 where still relevant.
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, use Python 3.6 with 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 may be needed to distutils to find the compiler.
Using
The separate generators are importable from randomgen
from randomgen import RandomGenerator, ThreeFry, PCG64, MT19937
rg = RandomGenerator(ThreeFry())
rg.random_sample(100)
rg = RandomGenerator(PCG64())
rg.random_sample(100)
# Identical to NumPy
rg = RandomGenerator(MT19937())
rg.random_sample(100)
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 (Uniform Doubles) ************************************************************ DSFMT 137.1% MT19937 21.0% PCG32 101.2% PCG64 110.7% Philox -2.7% ThreeFry -11.4% ThreeFry32 -62.3% Xoroshiro128 181.4% Xorshift1024 141.8% Speed-up relative to NumPy (64-bit unsigned integers) ************************************************************ DSFMT 24.8% MT19937 15.0% PCG32 92.6% PCG64 99.0% Philox -20.4% ThreeFry -21.7% ThreeFry32 -64.4% Xoroshiro128 164.2% Xorshift1024 120.8% Speed-up relative to NumPy (Standard normals) ************************************************************ DSFMT 299.4% MT19937 271.2% PCG32 364.5% PCG64 364.2% Philox 256.9% ThreeFry 236.0% ThreeFry32 97.0% Xoroshiro128 477.4% Xorshift1024 360.7%
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
File details
Details for the file randomgen-1.14.4-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ee15a566b7f6da8f2e29419bda92bc48ad47fb46e11bffd491033bd99e59f06 |
|
MD5 | 51398081895f182ca67248040c729245 |
|
BLAKE2b-256 | 235d0cf00491f0a6034bf26623913048c83d08f0e266aca748c87773a645b14f |
File details
Details for the file randomgen-1.14.4-cp36-cp36m-win32.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp36-cp36m-win32.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 467b31ad2581c95155c4a514351fda40874da7b99cdd64175e7498e87f850caa |
|
MD5 | 17314c1374b46ae3d5c5fccdb6e96447 |
|
BLAKE2b-256 | 508e823f8f9a421d060ccc530429fce80ca1774cc1e161e5d02008f047cddf8b |
File details
Details for the file randomgen-1.14.4-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d74466a556ef07c0bd2c242473e5e60806cd8d8c2aee700c7ba6a07840131ac6 |
|
MD5 | 30a09fd948465481dbf31354cb695871 |
|
BLAKE2b-256 | 756bce4bbcd219365f2e3cfd8bbfe51ed61f86f34951157c96fc2efcfd5ca47b |
File details
Details for the file randomgen-1.14.4-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0951429ea2e1392f651d7825e0c07100774f94245594d17867758ed90b9a30a |
|
MD5 | 783df3965fe87440f870d55fc7d6671d |
|
BLAKE2b-256 | 27b17f25a4e40c9ed3a784f381500bbcf347c8162ca3455a348bfc50780447f8 |
File details
Details for the file randomgen-1.14.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.6m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61a4d760e94b009a5cad7d75a3e44f8ce4c67533b7ae35e8656801ff0202fb11 |
|
MD5 | a9c97df2b100c8407eb7e4586d514533 |
|
BLAKE2b-256 | a3a17c16f5bfa30afe7902b24f7a22a5f476ae970d94427c67e0b84a027f3513 |
File details
Details for the file randomgen-1.14.4-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17203dae085b75af60909a1759299bd2858d7fd844e1cf998f03f53e42777414 |
|
MD5 | 43818b65729a8dad35cdbd67bb759626 |
|
BLAKE2b-256 | 43fffbb9dc6b5b9e797eae4ea6e6c4f5ca61e762b456c469a301ff23048bd31e |
File details
Details for the file randomgen-1.14.4-cp35-cp35m-win32.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp35-cp35m-win32.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ce1651160cb16efd3308237f2a9e404a08e65fe464bfc6f3682fc8e6ad8d5c |
|
MD5 | 08fbb26ecdde6ccc388bbc2c997e3ee4 |
|
BLAKE2b-256 | fdd538e06dfe16063362b77841a780322fff80be483af4de51abe798648e8076 |
File details
Details for the file randomgen-1.14.4-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38e320549dda9861b8ff75d0d674fb8a5221b715e11d54d5431a3c585def77d5 |
|
MD5 | cbeaf567df4336321c6cf624ada1d100 |
|
BLAKE2b-256 | 081c49664bee1fb96adc45f387b43b6bb000041beb4708172f3a58cb05bca84d |
File details
Details for the file randomgen-1.14.4-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4739bf38cd003558f1e469daa7e9b1ad57b01857d281b6aed45cfb007f155ab3 |
|
MD5 | c7f37b8de6f3292befeedc5869272fd0 |
|
BLAKE2b-256 | f9cd5dea639937b463a6bfc7cae87790eb7858ed4b2f85e7ad09857ed65c6645 |
File details
Details for the file randomgen-1.14.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.5m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f16c4d9fe0db2f06d92cd4ceaac55e8267111e0dd763e57ffc9c62a31f8436 |
|
MD5 | 89064a6ee5967a39bd7091ae7ffd45b2 |
|
BLAKE2b-256 | 3b7bf9f79556dc86b0a41709ce437ac5909e23ed8d4e9fe66ffa5fa1d21aba73 |
File details
Details for the file randomgen-1.14.4-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27mu-manylinux1_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0820952113e4ce0db56ed7849e41c9bb85256100cf0e28ff881a3fdbef48663 |
|
MD5 | 490027ff2beffa41cb5ff25cd12b2846 |
|
BLAKE2b-256 | 8597dd4235cc1c0966d8dffc64158f7dbde293a185eb84f6b6d45af3d008c0e7 |
File details
Details for the file randomgen-1.14.4-cp27-cp27mu-manylinux1_i686.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27mu-manylinux1_i686.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e7649d444cbdabba0f590d71515926bcb6708bc7092330765cf3efbfba59d5a |
|
MD5 | 15bb276da300c24535912a2300125c3a |
|
BLAKE2b-256 | 5874c826d19fd99fd009f73dfbf23f42596e5063caab76fe9fdfe90faad25ab7 |
File details
Details for the file randomgen-1.14.4-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e233fb059d950b389718f7719ae0aae28cc2aba321d4d3d6a532474ca860144f |
|
MD5 | 6b7d82a4d63110777e3ca51e6d90a3ae |
|
BLAKE2b-256 | a13e12ff9e699ea66e47f2fae8a0478bf868f048b529718163b9955370e1cb1a |
File details
Details for the file randomgen-1.14.4-cp27-cp27m-win32.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27m-win32.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4ed4b6dce2bb44e0113c3f467c0ab3dfea4e19a12b4d10873af1658adc16a0f |
|
MD5 | cfc2a79da05af242801ed6412f94dec3 |
|
BLAKE2b-256 | 1c1ab1d73514a88dc7fbbe2e5afc1d22d38099b1be2cd724dfa4299e2909e23f |
File details
Details for the file randomgen-1.14.4-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eaed8c254178a655e77ea51c623f94f14ee9aa5a114fc62b91e9f8df1b02411 |
|
MD5 | 9934d8e48e052463d76662d4a9e6c92f |
|
BLAKE2b-256 | a7aa6a2b08eb16b7dae4f64a1e914191cd6ba456678f2b8bc9fd29b30d8190d6 |
File details
Details for the file randomgen-1.14.4-cp27-cp27m-manylinux1_i686.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27m-manylinux1_i686.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5a14cd1ef0311f96b50b9742e62fd19b52e1d2f5ad61ebaa1da5a63e5f5297f |
|
MD5 | 7bccaeae44b0426e324590af2be1c198 |
|
BLAKE2b-256 | 6e8da680b4a03dcbc2c0633b72c80bbf55805fcf4b62ab747fcfc2fdc818495e |
File details
Details for the file randomgen-1.14.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: randomgen-1.14.4-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 2.7m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25aebedde86518c74303e282b3be2c8bd1c58f82ac8fa74992b99c4a3adb005c |
|
MD5 | 9f16365ac975fa21d0620978f1a0f6b0 |
|
BLAKE2b-256 | 2b555584d86c9543e3ec6f829ade0741e0aff84d1328781c8fd435c5862c825a |