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

RandomGenerator does notsupports 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:

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.3.tar.gz (586.7 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m Windows x86

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

Uploaded CPython 3.6m

randomgen-1.14.3-cp36-cp36m-manylinux1_i686.whl (1.6 MB view details)

Uploaded CPython 3.6m

randomgen-1.14.3-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.3-cp35-cp35m-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.5m Windows x86-64

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

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.5m

randomgen-1.14.3-cp35-cp35m-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 3.5m

randomgen-1.14.3-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.3-cp27-cp27mu-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 2.7mu

randomgen-1.14.3-cp27-cp27mu-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 2.7mu

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

Uploaded CPython 2.7m Windows x86-64

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

Uploaded CPython 2.7m Windows x86

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

Uploaded CPython 2.7m

randomgen-1.14.3-cp27-cp27m-manylinux1_i686.whl (1.5 MB view details)

Uploaded CPython 2.7m

randomgen-1.14.3-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.7 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.3.tar.gz.

File metadata

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

File hashes

Hashes for randomgen-1.14.3.tar.gz
Algorithm Hash digest
SHA256 cf77104c0dc36fdfa84e471fecead95ae48bf545a7aff452a4cb0fc4fa87bb72
MD5 5bef25f96c7fc34e15ac79c71005efab
BLAKE2b-256 4bfc0671c971ec188eb07ce606300b5b71b302ac3c7888f3e264bd6dcb8cef78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 17aa4233c712993e2e2ca9930ab56fa3d432e1fbc730ca363643d0c5b95c4222
MD5 ae455976efc3ffb78cce86313ab9b2e4
BLAKE2b-256 47a6b71a975f1ce9c9ed9912503aa2449a650a8799885e5a03d3858db8adb695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 0a47c8ef933eaa6fbe8a213ec4b5a3ea2e68cf855f033032c4e3837f804d3096
MD5 2bc72d6d4884084b567f2343e999d0fd
BLAKE2b-256 1185c8226d175b5574b44e47758a540bd09d0117ba4cd4145610df712fea7727

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 eaf98db67609d73d2749c1ac3cde07828106ca3577a96e7945fb2b290d1e30af
MD5 e1e085c170d91fb00cf11d4175dfba56
BLAKE2b-256 3df805d610755e87d54d5254f4113e1297b741b5f8f92a45967f304c8cd1a699

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for randomgen-1.14.3-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f30ae97b985b05b59364a06f6a1f470ac635b659b885b6fcaa3aa03b0ec74125
MD5 faa4b6e96180b52daacc3dd121ce0e5e
BLAKE2b-256 2f43448991dba2800d06412d86b28f1d4aacda4d9af7003da0468417bc3bd9b9

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-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.3-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 b433436b67c129a2073965810805c5c9459451bffa4661049e6b4b335172db3f
MD5 8a3778519698244607dcd224e06b6ce1
BLAKE2b-256 22066196c97701e619905d22541489a392750269e9144213138d854ececaafe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 81b8e0cfd7b482ec506f64f2a46fc6f3c9d45920de4115e20b958aef3210a234
MD5 6ae48f2d6c61cef28b13f3f801efb9fb
BLAKE2b-256 c32ac941fca3c371197568dc490ebd20c4d55575993616dd73070a2e7f84cc43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a8a87e3a229b6b7a77bb1cbc008c80206b7d72d99767207e1143259d6998c145
MD5 f1b9eb9195fcc6deb0f91df206fc60ba
BLAKE2b-256 e9070e24c05f9d3c5d8ff3f7505e445d9fe4fb455afa024d0e2c38efda6d75eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5bb1166f204bd781e61d67198513ae3a77c6561fd8e59042c0589ad9e719c728
MD5 114cb79704d059797d9474aa33feb4c7
BLAKE2b-256 78d071fc7d4c3573ff8fdf62ec1a0afe09f2678f132bc6bd1a8246dfb8537ff0

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for randomgen-1.14.3-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 6757596b81db746caa38c5463ceafa70500946601825573fc096c1acd88074f0
MD5 ed7d10540da6038cf8778cd6999d7af2
BLAKE2b-256 5c4a36137ca0f9683847443053085c30e4a9c376fac794de7b9086921d54c61e

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-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.3-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 b32c671daf62cdab0b0062b7e8328907fd5e53de2cdd7cf007bd73d68a72efb1
MD5 176a4d7efb1971fb12dfd0e5495c831e
BLAKE2b-256 c375600e6532ac4b4d19c81190ea3ec33944525ddb47378f9efd722cb008b318

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5408d54d494bb822989cd10d7404f84f0e0e0329f0a52275722047722c2dfea5
MD5 599ab056b264982fe83ac2cd00e4b425
BLAKE2b-256 8da01bf4db085dabe92f64b94414e5bd408505311165bd44f6840696858a1d60

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a3d059c7a935e76b9fb8d91f1b60c152d00dd6877ce2e5bb6ae819ffe16a763c
MD5 9b4b4bd43bf88dd9b1c73496fceef771
BLAKE2b-256 d671e0328eab1f9f8e1e58ebe29993bbc46fe5c45d949553695987e4504a9489

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 35e653f77d061f672c7d088174be4f5280764a8debadb6d2b74070184ae1ceac
MD5 88596b3fa8368bb8bd9104ddbf6772af
BLAKE2b-256 478d8b88e7996c251987d4c2cfc84398ecd32fb33114cdd512b145251683e1b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 a3bfe9d8249702aec73b71744ed3c33a73c3fcc5dadc0960f8b9b0230f6f6c7e
MD5 f4daf2dd5bfd1b0f1808aac5e5dc916c
BLAKE2b-256 f9e89c3a37b99798f765f031e6a041451263c1c94a2e81de94ba63630388ccdf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0a907c660049e6f16ad90ba772ec2b478e410e3de4558bb357e21f578ea47cf8
MD5 27b6ce0ca631b74dffc529d5f0dee476
BLAKE2b-256 fd9c2ff84a9a0cb5e4e114430096eea714ea3e610b7a6776037bb4c886551664

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for randomgen-1.14.3-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9cf55c2dc824033a64c93a44c37a866403fadf8e28fc246d7a6dedc4ffef1d5f
MD5 c325eeca170c3b6e2473cfd8cfa7df7a
BLAKE2b-256 441b1fec63664f529b78f159b34db6ebbfc115de1f1431d0a1fe37ce90349fe4

See more details on using hashes here.

File details

Details for the file randomgen-1.14.3-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.3-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 4bb24e3265c5877d856e5e2143794ebf36e4253566c2910f27ba280ef6b84bcf
MD5 8ecf60aa1423ba2c38331df68402f072
BLAKE2b-256 40237d4a408dda29d159f6940cb173e853c5ea08573ba3a342b902a9e9063541

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