Skip to main content

Random number generator with eXtra Entropy

Project description

This little module is a simple and reliable way to improve randomness of any random or pseudo-random number generator.

We never being 100% sure in real randomness and cryptographic quality of any externally-provided RNG, and this is a good idea to be able to add some addition entropy to by own hands. This module provides following features:
1. Easy way to combine unrestricted number of randomness sources (CompoundRandom class).
2. Tool to transform several additional bytes of extra entropy into complete random-like mess (HashRandom class).

### Why we can be sure that combining independent random sources can only improve quality of RNG
<coming soon...>

### How to embed

There are two ways to embed this functionality into your project:
1. Get this module by `pip install random_xe` and then import into your module by `import random_xe`.
2. Directly download [](/ file and adopt it into your project.

### How to use

Import this module:
>>> import random_xe
Create and try HashRandom PRNG initialized with 'Hello world':
>>> import random_xe
>>> myrandom1 = random_xe.HashRandom('Hello world')
>>> myrandom1.randint(100, 200)
>>> myrandom1.gauss(20, 10)
myrandom1 uses SHA-256 hashing function (option by default).

Let`s try to combine this PRNG with another HashRandom based on SHA3-512 and initialized from user input:
>>> from hashlib import sha3_512
>>> myrandom2 = random_xe.CompoundRandom(myrandom1, random_xe.HashRandom(input('Type somethig: '), sha3_512))
Type somethig: ldjggndjKfuT830
>>> myrandom2.getrandbits(128)

It is very good idea ALWAYS combine additional entropy with SystemRandom source:
>>> from getpass import getpass
>>> from time import perf_counter
>>> # Three sources:
>>> # - SystemRandom;
>>> # - user input;
>>> # - timing.
>>> def super_myrandom():
t_start = perf_counter()
return random_xe.CompoundRandom(random_xe.SystemRandom(),
getpass('Type somethig:'), sha3_512),
random_xe.HashRandom(perf_counter() - t_start))

>>> myrandom3 = super_myrandom()
>>> myrandom3.getrandbits(128)

Keywords: random rng prng
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Description-Content-Type: text/markdown

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for random-xe, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size random_xe-1.0.0.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page