sourcerandom for Python
True randomness, with minimal fuss.
Alternate random number generator using sources provided by either True Random Number Generator online services (RANDOM.org and qrng.anu.edu.au), plaintext uint8 files (separated by whitespace) or collections of ints.
sourcerandom's SourceRandom class extends SystemRandom class found in default random package, and only overwrites the getrandbits method, meaning all of the functionality of random package is included and unchanged.
sourcerandom obtains bytes from the given source, which are then used to generate random numbers. The bytes are cached for quick access - the amount of cached bytes can be set by the user.
OnlineRandomnessSource enumerator is provided to easily choose between RANDOM.org (RANDOM_ORG) and qrng.anu.edu.au (QRNG_ANU).
Since the bytes generated by the online services are truly random (please refer to the services for explanation), they can be theoretically used for cryptography instead of OS sources. However, I hold no responsibility for any problems or damages this may cause.
Async/multithread friendly.
Requires Python 3.5.2 or above, and the requests package.
Pull requests are encouraged :D
Installing
pip install sourcerandom
Usage
import sourcerandom
# From an online source
RAND_GEN = sourcerandom.SourceRandom(source=sourcerandom.OnlineRandomnessSource.QRNG_ANU) # Initialize the generator - use the same generator to take advantage of caching
print(RAND_GEN.randint(0, 20)) # Every method from random package is included
# From file
RAND_GEN = sourcerandom.SourceRandom(source="path/to/file") # File has to be a plaintext file with integers from range of 0 to 255 separated by whitespace, path is a simple string, relative to working directory. Files are read in cache_size chunks.
# From collection
BYTES_LIST = [ 0, 156, 245, 63, 52 ] # Integers from range of 0 to 255 separated by whitespace
RAND_GEN = sourcerandom.SourceRandom(source=BYTES_LIST)
Metadata
Release files for sourcerandom 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sourcerandom-1.0.2.tar.gz | 6.1 kB | Without provenance | Details for sourcerandom-1.0.2.tar.gz |
Release files / sourcerandom-1.0.2.tar.gz
| Download URL | sourcerandom-1.0.2.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20aac8b05e632307630b26d88b527acbe7cea7c6fd892f0bd797ee30f795b1f7
|
|
BLAKE2b-256 checksum How to use checksums |
1bd94d1186ecff37b29dfdf81936df77f6514a4239f09fbe557b1438bafd213a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sourcerandom 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.