useless random libary
Project description
xorandom
Overview
xorandom is a lightweight, fast pseudo-random number generator (PRNG) library implemented in Python, inspired by xorshift algorithms. It provides functions for generating random integers, floats, bit sequences, and other utilities compatible with Python’s random module API.
The library is designed for deterministic behavior with explicit seeding, making it suitable for simulations, procedural generation, and reproducible testing.
Example Usage
import xorandom
def main():
# Seed + basic RNG calls
xorandom.seed(0xDEADBEEF)
print("randuint64():", xorandom.randuint64())
print("randbits(20):", xorandom.randbits(20))
print("getrandbits(16) alias:", xorandom.getrandbits(16))
print("randbelow(100):", xorandom.randbelow(100))
print("random():", xorandom.random())
print("uniform(1,5):", xorandom.uniform(1,5))
# Discrete random values / indices
print("randint(1,6):", xorandom.randint(1,6))
print("randrange(0,10,2):", xorandom.randrange(0,10,2))
# Selection / permutation / sampling
seq = [1, 2, 3, 4, 5]
print("choice(seq):", xorandom.choice(seq))
arr = [1, 2, 3, 4, 5]
xorandom.shuffle(arr)
print("shuffle ->", arr)
print("sample([10,20,30,40], 2):", xorandom.sample([10,20,30,40], 2))
# choices: unweighted (replacement) & weighted (replacement)
print("choices unweighted k=5:", xorandom.choices(['a','b','c'], k=5))
print("choices weighted k=5:", xorandom.choices(['a','b','c'], k=5, weights=[0.1,0.7,0.2]))
# Gaussian / Normal distribution (Box-Muller transform)
print("normalvariate(0,1):", xorandom.normalvariate(0,1))
print("gauss(10,2):", xorandom.gauss(10,2))
# Exponential distribution
print("expovariate(0.5):", xorandom.expovariate(0.5))
# Characters / strings / bytes
print("randsymbol():", xorandom.randsymbol())
print("randchar_from_charset('abc'):", xorandom.randchar_from_charset('abc'))
print("randstr(8):", xorandom.randstr(8))
print("random_from_spec('1sS%'):", xorandom.random_from_spec('1sS%'))
print("randbytes(6):", xorandom.randbytes(6))
# State save / restore -> demonstrate reproducibility
state = xorandom.getstate()
print("saved state:", state)
v1 = xorandom.random()
xorandom.setstate(state)
v2 = xorandom.random()
print("reproducible? ->", v1 == v2, "values:", v1, v2)
if __name__ == "__main__":
main()
Features
- Fast xorshift-based random number generation.
- Compatible with Python’s
randomAPI (seed,random,randint, etc.). - Support for integer, float, bit-level, and distribution-based generation.
- Deterministic seeding and state restoration.
- Efficient sampling, shuffling, and character/byte generation.
API Reference
Core Functions
seed(value: int)— Initialize the generator with a seed.randuint64() -> int— Generate a 64-bit unsigned random integer.randbits(k: int) -> int— Return an integer withkrandom bits.getrandbits(k: int) -> int— Alias forrandbits.randbelow(n: int) -> int— Random integer in[0, n).random() -> float— Random float in[0.0, 1.0).uniform(a: float, b: float) -> float— Random float in[a, b].
Discrete and Distribution Functions
randint(a: int, b: int)— Random integer betweenaandbinclusive.randrange(start, stop[, step])— Random integer from range.normalvariate(mu, sigma)— Normal distribution (Box–Muller transform).gauss(mu, sigma)— Alias fornormalvariate.expovariate(lambd)— Exponential distribution.
Sequence and Sampling Functions
choice(seq)— Random element from a sequence.shuffle(seq)— Shuffle sequence in place.sample(population, k)— Random sample of sizek.choices(population, k, weights=None)— Random selection with replacement.
String and Byte Functions
randsymbol()— Random alphanumeric symbol.randchar_from_charset(charset)— Random character from a given charset.randstr(length)— Random string of given length.random_from_spec(spec)— Random string matching a character specification.randbytes(length)— Random byte sequence.
State Management
getstate()— Get current generator state.setstate(state)— Restore generator state.
License
This library is distributed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xorandom-0.1.0.tar.gz.
File metadata
- Download URL: xorandom-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bcf8a836e5f8e1cb8bbab518d22d489cffe59c2a310f54efb3ac9a52ac28313
|
|
| MD5 |
f60b7dd350e97af3b3a7461b28bf57dc
|
|
| BLAKE2b-256 |
2efdb13064f66e7317dc1d803bd8887ee00c3de8feb4b1bd8d8c9b05c8ec2d2c
|
File details
Details for the file xorandom-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xorandom-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e740675a146a90f932346d1bb41f34f3425d3359de5247af2e467af3f8e63a3
|
|
| MD5 |
093825ec13803294b9e290f52ec631bb
|
|
| BLAKE2b-256 |
36fe6855258a3444fe7093b687ba1fdcd5410fbbbb8b0a0f1299e0a3a214833d
|