Skip to main content

Provide several randomness sources in Python with a common API

Project description

Randomness Sources for Python

Current Features

  • unified API to randomness sources
  • API access to the system's true randomness generator
  • a list of randomness providers to choose from
  • provider flags which you can filter for

Planned Features

  • comprehensive tests for randomness quality (dieharder, ENT, ...)
  • more PRNGs (Wichmann-Hill, xorshift, ...)
  • more TRNGs (VIA Padlock RNG, external hardware, ...)
  • better API to filter and sort providers
  • choice between wasteful and conserving usage of random bits, the latter most likely with a mixin
  • adapter to provide the Numpy API for all randomness sources, most likely by way of a mixin

Usage

You can instantiate a randomness source directly if you know it's there (or if you handle the exception in case it's not):

from randomness import URandom

try:
    from randomness import Random

except ImportError:
    pass

random = URandom()

Or you can peruse the list of providers and select one out of those (possibly filtering the list first):

from randomness import PROVIDERS, ProviderFlag

# filter randomness providers
my_providers = [provider for provider in PROVIDERS
                if provider.flags & ProviderFlag.NEVER_BLOCKING]

# dump provider names
for provider in my_providers:
    print(provider.name)

# instantiate a randomness context
chosen_provider = my_providers[0]
random = chosen_provider.cls()

From this point forward usage is the same as if you had done from random import Random; random = Random().

# perform a die roll
die_result = random.randint(1, 6)
print(die_result)

# select a random cheese
CHEESE_SHOP_PRODUCTS = ["Tilsit", "Cheddar", "Roquefort", "Gouda"]
cheese = random.choice(CHEESE_SHOP_PRODUCTS)
print(cheese)

# draw lottery numbers
amount_of_numbers = 49
amount_to_draw = 6
series = random.sample(range(1, amount_of_numbers + 1),
                       amount_to_draw)
print(series)

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

randomness-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

randomness-0.2.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file randomness-0.2.0.tar.gz.

File metadata

  • Download URL: randomness-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.0 CPython/3.6.7rc1

File hashes

Hashes for randomness-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c0368c868379d3da6237c789f5fb7039f0bf92c6eb9f5b4b0f38053efd03902f
MD5 6f07f0056f74b750a8cad90cab3e39bc
BLAKE2b-256 94c5f2fe5bafb0f60cd38d42c465c1d977bbcb82e9715bdafd60a2f724437c82

See more details on using hashes here.

File details

Details for the file randomness-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: randomness-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.0 CPython/3.6.7rc1

File hashes

Hashes for randomness-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c25a9a5d41e2e53c4316cea7b957535a102113f597fe57b2bcc04b89488b330
MD5 4e006b308f6fac0398b124858f0e777b
BLAKE2b-256 a9e255dfdfe63947adb488fae01293ae1c7c8e99283952c8f277ea5f7632dea4

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