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.10.46.tar.gz (7.4 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.10.46-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stablerandom-0.10.46.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for stablerandom-0.10.46.tar.gz
Algorithm Hash digest
SHA256 5f684b03ec6642f5f8594b24b35885fb172af2630f59e9a0f00d7925501af3bb
MD5 87f3911457cda675bafe6c5d430544cd
BLAKE2b-256 7fd51eb56c66543e9a102c82f1142e743aa3fd32a0c075e7fc7ad592aa09d241

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stablerandom-0.10.46-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for stablerandom-0.10.46-py3-none-any.whl
Algorithm Hash digest
SHA256 c45671914a89f86e35db1285781e8fabd672e9e01e406963c428c7913ad47b2f
MD5 b3ac73cc2cc584f9b20bdd4d433b9013
BLAKE2b-256 d123254dc901cc5cf38be9c048dbccdf798205b8b96365749e788e34114f8df4

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