Skip to main content

Create stable/repeatable numpy.random applications

Project description

stablerandom

stablerandom provides a stable and repeatable implementation of the NumPy random number generator (numpy.random). With this package, you can generate the same sequence of random numbers across different platforms and Python environments, ensuring reproducibility in scientific computing, machine learning, and unit testing.

stablerandom can decorate any function or method and provide a call-stack scoped seeded random generator. stablerandom can also be used as a Context. It is thread safe and supports nested scopes.

Example decorator

Using the @stablerandom decorator to get a stable output for numpy.random.triangular

import numpy.random
from stablerandom import stablerandom

@stablerandom
def random_triangular(samples):
   return numpy.random.triangular(1, 5, 10, samples)

print(random_triangular(3))
>>> [5.1017943  2.64970963 8.6996913 ]
print(random_triangular(3))
>>> [5.1017943  2.64970963 8.6996913 ]

Example context

Using the with stablerandom context to get a stable output:

import numpy.random
from stablerandom import stablerandom

with stablerandom:
    print(numpy.random.triangular(1, 5, 10, 3))
    print(numpy.random.triangular(1, 5, 10, 3))
>>> [5.1017943  2.64970963 8.6996913 ]
>>> [3.30538708 2.39427919 3.57653224]

with stablerandom:
    print(numpy.random.triangular(1, 5, 10, 3))
>>> [5.1017943  2.64970963 8.6996913 ]

Installing

$ pip install stablerandom

The source code is currently hosted on GitHub at https://github.com/GistLabs/stablerandom and published in PyPI at https://pypi.org/project/stablerandom/

The versioning scheme currently used is {major}.{minor}.{auto build number} from git rev-list --count HEAD.

We recommend picking a version like:

stablerandom = "^0.5"

Dependencies

This library has been tested with NumPy back to version 1.22

Community guidelines

We welcome contributions and questions. Please head over to github and send us pull requests or create issues!

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

stablerandom-0.6.45.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

stablerandom-0.6.45-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file stablerandom-0.6.45.tar.gz.

File metadata

  • Download URL: stablerandom-0.6.45.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1038-azure

File hashes

Hashes for stablerandom-0.6.45.tar.gz
Algorithm Hash digest
SHA256 e6dfdfefe8b91b554c69de3d7da5e64c0c3a5dd66c0d89968e0bd5fef92edfd5
MD5 2236b90995c2263751c67738cee075b5
BLAKE2b-256 4a58e35e0a2db01b46e99e41bdd60b17856ce1985aea169058bdc490c8609411

See more details on using hashes here.

File details

Details for the file stablerandom-0.6.45-py3-none-any.whl.

File metadata

  • Download URL: stablerandom-0.6.45-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1038-azure

File hashes

Hashes for stablerandom-0.6.45-py3-none-any.whl
Algorithm Hash digest
SHA256 5472c6e484fd9fd504ab87137f5fe1b7eb0e75b2955f69bc17cf59115886779b
MD5 f74061bf0cacf381c032111e9b1d3226
BLAKE2b-256 f122366e5d75f2729828b081b2dfbbbb19a0dc7097c04f8fafba0b8650e303af

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