Proof-of-concept seeded RNG lib
Project description
seedrandom
Deterministic seeded RNG
Installation / Updating
pip install seedrandom
pip install --upgrade seedrandom
Or
pip install git+https://github.com/BananaLoaf/seedrandom.git
pip install --upgrade git+https://github.com/BananaLoaf/seedrandom.git
Usage
from seedrandom import SeededRNG
rng = SeededRNG(b"Test", b"values", hash_func=hashlib.sha512) # any hash func from hashlib
Generating random values:
rng.randint(a=0, b=1000) # 893
rng.randfloat(a=0, b=100, step=0.1) # 89.3
rng.randbool() # False
rng.randbyte() # b'\xbf'
SeededRNG
can be converted to and from int
or bytes
:
bytes(rng)
int(rng)
rng1 = SeededRNG.from_bytes(b'\xbb\x9a\xf3\xe3\x1d\xfcA\xcc\xc5\x93S\x9a\xec:\x9a\x08z\x88\x85\x99\xf7\xea\x91\xb6x\x00\xfb\x82"\xc2$K', hash_func=hashlib.blake2s)
rng2 = SeededRNG.from_int(13391421701272821393603640485300504071883816826531413055648909144818643814535822212998295950921452703111178763035507290455800978052021014498426299707601814, hash_func=hashlib.sha512)
ordered
parameter can be used:
rng1 = SeededRNG(b"Hello", b"world")
rng2 = SeededRNG(b"world", b"Hello")
rng1 == rng2 # True
rng1 = SeededRNG(ordered=(b"Hello", b"world"))
rng2 = SeededRNG(ordered=(b"world", b"Hello"))
rng1 == rng2 # False
rng1 = SeededRNG(b"Hello", b"world", ordered=(b"spanish", b"inquisition"))
rng2 = SeededRNG(b"world", b"Hello", ordered=(b"spanish", b"inquisition"))
rng1 == rng2 # True
rng1 = SeededRNG(b"Hello", b"world", ordered=(b"spanish", b"inquisition"))
rng2 = SeededRNG(b"Hello", b"world", ordered=(b"inquisition", b"spanish"))
rng1 == rng2 # False
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
seedrandom-2.3.1.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file seedrandom-2.3.1.tar.gz
.
File metadata
- Download URL: seedrandom-2.3.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.13 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f7ca322efe13ce4d3af28c9541b24b1945f63d5040e55479aadb45cad96696 |
|
MD5 | 7acc20cccbcb6505814a485e5bda6743 |
|
BLAKE2b-256 | 9f4505b800d1b070b1e805f71e59bcf5865178c6e58aa9d006d0539e373f45a9 |
File details
Details for the file seedrandom-2.3.1-py3-none-any.whl
.
File metadata
- Download URL: seedrandom-2.3.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.13 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5269632b66c9d7988cd6143a9f53510cd7d9fc06c90aefe92741f68fd0d90d5f |
|
MD5 | 3db4987465d02cb9a5bf4af6e6bc10e7 |
|
BLAKE2b-256 | 481e422b52d2c82116f948bbae1715661b58a218dfedac2d0dfc6c5f4da735b8 |