Skip to main content

A package for generating and assessing randomness.

Project description

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.7.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.7-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: randomity-0.5.7.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.7.tar.gz
Algorithm Hash digest
SHA256 03ca794a20452e0c60812ac96708105f83c4c05868fb0142bce005d2b61aa3c6
MD5 af54e1e21148ff8d9480923d5485eee4
BLAKE2b-256 b2be8a547eb3e1220da3ed4eb3f5f57c8896935f8147d9d59cd2fceb8129dd13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: randomity-0.5.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2f216055bfceb017dfc32f009c2667163d7cd517a2fa65a87f99ca7401eea96f
MD5 9d05c96ec2183c5012a272037e00bc6c
BLAKE2b-256 c01fb5f3520ac5e3d3177fbe7267bf9d4e96ad0b96e0b325b7d1136e2b3aace1

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