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.
Metadata
Release files for xorandom 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xorandom-0.1.0.tar.gz | 8.4 kB | Without provenance | Details for xorandom-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xorandom-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for xorandom-0.1.0-py3-none-any.whl |
Total release size: 17.1 kB
Release files / xorandom-0.1.0.tar.gz
| Download URL | xorandom-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bcf8a836e5f8e1cb8bbab518d22d489cffe59c2a310f54efb3ac9a52ac28313
|
|
BLAKE2b-256 checksum How to use checksums |
2efdb13064f66e7317dc1d803bd8887ee00c3de8feb4b1bd8d8c9b05c8ec2d2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / xorandom-0.1.0-py3-none-any.whl
| Download URL | xorandom-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e740675a146a90f932346d1bb41f34f3425d3359de5247af2e467af3f8e63a3
|
|
BLAKE2b-256 checksum How to use checksums |
36fe6855258a3444fe7093b687ba1fdcd5410fbbbb8b0a0f1299e0a3a214833d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for xorandom 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.