Skip to main content

Random generator supporting multiple PRNGs

Project description

Travis Build Status Appveyor Build Status PyPI version

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

RandomGen no longer supports 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.

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:

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

Documentation for the latest release is available on my GitHub pages. Documentation for the latest commit (unreleased) is available under

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


Download files

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

Source Distribution

randomgen-1.14.2.tar.gz (588.4 kB view details)

Uploaded Source

Built Distributions

randomgen-1.14.2-cp36-cp36m-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.6m Windows x86-64

randomgen-1.14.2-cp36-cp36m-win32.whl (2.5 MB view details)

Uploaded CPython 3.6m Windows x86

randomgen-1.14.2-cp36-cp36m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.6m

randomgen-1.14.2-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 (1.6 MB view details)

Uploaded 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

randomgen-1.14.2-cp35-cp35m-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.5m Windows x86-64

randomgen-1.14.2-cp35-cp35m-win32.whl (2.5 MB view details)

Uploaded CPython 3.5m Windows x86

randomgen-1.14.2-cp35-cp35m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.5m

randomgen-1.14.2-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 (1.6 MB view details)

Uploaded 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

randomgen-1.14.2-cp27-cp27mu-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 2.7mu

randomgen-1.14.2-cp27-cp27m-win_amd64.whl (2.6 MB view details)

Uploaded CPython 2.7m Windows x86-64

randomgen-1.14.2-cp27-cp27m-win32.whl (2.5 MB view details)

Uploaded CPython 2.7m Windows x86

randomgen-1.14.2-cp27-cp27m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 2.7m

randomgen-1.14.2-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 (1.6 MB view details)

Uploaded 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

File details

Details for the file randomgen-1.14.2.tar.gz.

File metadata

  • Download URL: randomgen-1.14.2.tar.gz
  • Upload date:
  • Size: 588.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randomgen-1.14.2.tar.gz
Algorithm Hash digest
SHA256 15952d4f5ad15b332548276a21c34b9b6c50e61a46f71e27bbf2f11032fc37bc
MD5 8602e548e84afca55059fd6f8b342624
BLAKE2b-256 6e4e586f22a69ce8b00beb75a8a9d924d231a741dbaebd42f43e0428745378fd

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d1bfcb3e643b5f67f09378f21d153537ea8e9075ae75d4438c0594f126f184fc
MD5 eba3545e72c3777fdac903a96d5afecc
BLAKE2b-256 0d6e2896a7578497e372df15172e2b4178bddfe2241d3de303d428df10eb12c9

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 dc58d5b1eb6aaad1282771f56d105fa15cd7d9ad3214fde5bb16d17f27c0d1ed
MD5 67985b7cf141b53550ac40561efe9926
BLAKE2b-256 ef1940b4b0aaeacd762efc7502aa0cfb72d92d8413954df8d21e37e5dfa67527

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6120eac3468a127f61ee5dc48ad40ba04113d5894d489e9aedcc85933158428e
MD5 fdecab8dbe0e39b514db9e4141112742
BLAKE2b-256 067aa2e37f450b3deda7821e0dd92a64063b05acd6bfd3c8d75511afdd61990b

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-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

File hashes

Hashes for randomgen-1.14.2-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
Algorithm Hash digest
SHA256 29f35ac07cd3a9ecae5ebb71493b8eea0add777bdde9c918ea58844d8c078cd0
MD5 ebfddc97bc13ab3787d958b0f2bc2016
BLAKE2b-256 0260f02dc27504f98a98c6e9e16ae27ffebc090f828d337db941f441d2e1645d

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 128de07c42635b1e29296f6d3838a05239e7ccbecf6ea46fe1b0faf6f9e0155a
MD5 526b9cb68c7d0886ede713fd139a369f
BLAKE2b-256 d09aa3256e7ea0b54bda78c32ffb9cc1fdf07d5a75d0a6046c94d80ba362c74a

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 5ee4a80b649f381c861a7b54cc08fed432c4b7b0eca96dd84db8dcb72bacbe30
MD5 8c4fb813be98121a264118a1e31734e3
BLAKE2b-256 f4cc227b3975ce9d7f37e8b601a26a3d7442d70019c29d2e4f8e035cd33defab

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7841fac898a46d220ba8dafd775c12b112235119ac9a0337931b0ad8aae12d8d
MD5 722e188045af5fa254c0b514e5ddf8bc
BLAKE2b-256 5f378a9b1a5eee600eb9d5cee85ceb0c2b30271981dd3b3344b031131dabcf93

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-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

File hashes

Hashes for randomgen-1.14.2-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
Algorithm Hash digest
SHA256 1c43cec5d9ddc2866469fd4bb0697ab080bfae5116f1f6cbd6cedd170793d55e
MD5 76b70549eb731756ed74edd82450bdb8
BLAKE2b-256 2ecfcbe51e2fe09840e3bcbe2e7279ba5fd6f0d6817f6ac75a8639f3573b53d9

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a3240f16ed74f7d4413201d7b4791fa0c556e86fc48c8ea2794c86d0200802d6
MD5 2b6b6197ab9a0fbc20e2c6f66f03c42d
BLAKE2b-256 b4ccb4de42c314c4e64acfd17d407e098bd334c14626b0c058a7253b0ad758ee

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 ea2876e7e05abc71c24da4a7c58fd28fee0b1779f777f00d35102ed1f354235c
MD5 1980f931478c1a284f55d0e7ab283b87
BLAKE2b-256 2749688e7f1852127536b95cd7ea3a5b9162cfa2ebb26c97c404f82b5c1e1887

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 9a84c1a7ca62fd44d14ab559d8b9cd961d7f408d2610cc684c43b051f555e9b0
MD5 b8d73a790adf5cb7b2c5f460101454d3
BLAKE2b-256 293cc2c1bdb6adba7225033ba274eab43c7c9380307b6c3f3689d8a137d114f8

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for randomgen-1.14.2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d15d7c95ecda3a0c8939f43d882ef88932a847ce728081598a7fec55ed95d956
MD5 ac5b9f4f651315a1df8e8c5244826528
BLAKE2b-256 ee519c9b60c539ec35689811b251622fa5f0daa0cf2aa009256b699ffa9f8e9c

See more details on using hashes here.

File details

Details for the file randomgen-1.14.2-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

File hashes

Hashes for randomgen-1.14.2-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
Algorithm Hash digest
SHA256 6a8580f2c9328d2aab773cdfceae8e60f51d9f0a329d4ae90ffdedd33b4f7212
MD5 934e15172f9d0e73b3c8066213441099
BLAKE2b-256 476f0304358daca867c3a1844ec8a5376f62a4a885052051318818edb52c0f57

See more details on using hashes here.

Supported by

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