Library of random related utilities, based on the ChaCha20 stream cipher
Project description
ChaCha20-Generator-Utilities - Python
Uses the ChaCha20 implementation in pycryptodome https://pycryptodome.readthedocs.io/en/latest/ as a base for various functions related to random number generation.
The actual file is chacha20_generator.py inside the folder "clcert_chachagen", but we structured it this way to make use of setup.py and make the python version a proper package.
Install package
$ pip install clcert_chachagen
Examples
import clcert_chachagen as chachagen
# Create a chacha object with a zeros seed
chacha_zero = chachagen.ChaChaGen()
# Create a chacha object with a seed (hexadecimal)
chacha = chachagen.ChaChaGen("5ee5e2327a68a9db8a78efdaa855d102ed8bf14e128e0a72ae1c9d72e5f9747e27479f21dfbfd501")
# Get a float in [0, 1)
chacha.random() # 0.47738372261817247
# Get 3 random bytes
chacha.getbytes(3) # b'\\1N'
# Get 5 random bits (an integer between 0 and 2^5 - 1)
chacha.getrandbits(5) # 9
# Get a number between [1, 100]
chacha.randint(1, 100) # 71
# Shuffle an array
chacha.shuffle([1,2,3,4]) # [4, 1, 3, 2]
# Get a single random element from an array
chacha.choice([1,2,3,4]) # 3
# Get an array of 5 elements from a given array. The elements could be repeated.
chacha.choices([1,2,3,4], 5) # [4, 3, 1, 4, 4]
# Get an array of 3 elements from a given array. The elements can't be repeated.
chacha.sample([1,2,3,4,5], 3) # [4, 5, 3]
# Reseed (essentially the same as creating an entirely new one with the new seed)
chacha.reseed("8ee5e2327a68a9db8a78efdaa855d102ed8bf14e128e0a72ae1c9d72e5f9747e27479f21dfbfd501")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clcert_chachagen-1.1.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for clcert_chachagen-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3732ed78740c866cdf594fd71482b19c009afb48bdac7259c98ca68aee6943 |
|
MD5 | 047abb1fe6dd4ee3dad415895e42e3a1 |
|
BLAKE2b-256 | 39c2ee3c08deb8fa69767a2878c4ddd57709fae5a999f7f0a3ef14c7ef25d79b |