Skip to main content

A package for generating and assessing randomness.

Project description

randomity

randomity is a comprehensive statistical suite and Python library designed to measure the unpredictability of pseudo-random number generators (PRNGs) and true random number generators (TRNGs). The package provides tools to generate sequences using industry-standard algorithms, implement quantum-generated randomness via Qiskit, and evaluate those sequences across multiple statistical dimensions to compute a composite randomness score.

The project implements several generation strategies, including Linear Congruential Generators (LCG), Mersenne Twister, XORShift, Blum Blum Shub, and Middle Square algorithms, alongside a Quantum Random Number Generator (QRNG) that leverages single-qubit measurement collapse.

Approach

The core of the package is a multi-dimensional evaluation engine that categorizes randomness into three primary paradigms: Uniformity, Patterns, and Periodicity. Each paradigm was evaluated using a suite of statistical tests. To provide a clear assessment, randomity implements a normalization pipeline that maps disparate statistical metrics (such as p-values and spectral magnitudes) onto a standardized $[0,1]$ scale. These normalized values are then synthesized into a composite Randomness Score, allowing for a direct, comparative evaluation of different generators.

Usage

To install and use randomity:

pip install randomity

Evaluating a Sequence

You can use the isRandom function to determine if a sequence meets a specific unpredictability threshold (default is $0.6$):

from randomity.evaluate import isRandom

# A sample sequence of numbers
my_sequence = [7, 1, 0, 4, 1, 9, 3, 2, 8, 5]

# Returns a boolean based on the composite score
result = isRandom(my_sequence, threshold=0.6)
print(f"Is it random? {result}")

Generating Random Sequences

The package provides dedicated modules for both pseudo and quantum generation:

from randomity.generate import pseudo, quantum

# Generate a sequence using the Mersenne Twister algorithm
prng_seq = pseudo.mersenne_twister(n=1000)

# Generate a sequence using a Quantum Random Number Generator (requires qiskit)
qrng_seq = quantum.qrng(n=100)

Inspection

For a deeper look into why a sequence passed or failed, you can inspect the individual scores for each paradigm:

from randomity.evaluate import inspectRandom

# Get a dictionary of sub-scores for Uniformity, Patterns, and Periodicity
report = inspectRandom(my_sequence)
print(report)

Contributing

To contribute to this project, you can fork this repository and create pull requests. You can also open an issue if you find a bug or wish to make a suggestion.

License

This project is licensed under the GNU General Public License (GPL).

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

randomity-0.5.4.tar.gz (640.1 kB view details)

Uploaded Source

Built Distribution

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

randomity-0.5.4-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file randomity-0.5.4.tar.gz.

File metadata

  • Download URL: randomity-0.5.4.tar.gz
  • Upload date:
  • Size: 640.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.14

File hashes

Hashes for randomity-0.5.4.tar.gz
Algorithm Hash digest
SHA256 5e8be475ebae369f93a199401bbb16a6525b7e96bf22fb78d28482f13b74e16d
MD5 3f83cf6359d2609b2000275b25146322
BLAKE2b-256 cf06762b439ee3fc5120f3c1c7cf76e9b3829a28fbf38fc1ebb2a9e5c91a31d5

See more details on using hashes here.

File details

Details for the file randomity-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: randomity-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.14

File hashes

Hashes for randomity-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c01563a84e370f0ac17f4559a800654d9d5c83914659bdb41dca131f42a9df95
MD5 0e702948ec6cc79c911cbf639e149f7e
BLAKE2b-256 883a514a2f30f39d4e55e29a253bfa9b6fe35b6b4f8f968eb66e1c1a31cb149c

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