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 [random_xe.py](/random_xe.py) file and adopt it into your project.

### How to use

Import this module:
```python
>>> import random_xe
```
Create and try HashRandom PRNG initialized with 'Hello world':
```python
>>> import random_xe
>>> myrandom1 = random_xe.HashRandom('Hello world')
>>> myrandom1.randint(100, 200)
156
>>> myrandom1.gauss(20, 10)
8.243867125227318
```
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:
```python
>>> from hashlib import sha3_512
>>> myrandom2 = random_xe.CompoundRandom(myrandom1, random_xe.HashRandom(input('Type somethig: '), sha3_512))
Type somethig: ldjggndjKfuT830
>>> myrandom2.getrandbits(128)
171962833922528548054430533031273437533
```

It is very good idea ALWAYS combine additional entropy with SystemRandom source:
```python
>>> 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(),
random_xe.HashRandom(
getpass('Type somethig:'), sha3_512),
random_xe.HashRandom(perf_counter() - t_start))

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

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.

Source Distribution

random_xe-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file random_xe-1.0.0.tar.gz.

File metadata

  • Download URL: random_xe-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.3

File hashes

Hashes for random_xe-1.0.0.tar.gz
Algorithm Hash digest
SHA256 edc0afe1ec38cd8d28052a2ae2977c4a786386cf5975ef80b8da4871a42b5ec6
MD5 edecceed533aa03e42c6fc42eeca1977
BLAKE2b-256 8590dc82a027817cd13a59c8b229f54651f9acf52ffd05f2d17fd6c623713793

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page