Skip to main content

rngpro

Fast, seedable pseudorandom number generation for Python — multiple PRNG engines, statistical distributions, reservoir sampling, and OS-backed secure helpers.

Author: Frank Herniszis · License: MIT

pip install rngpro

Features

  • Three PRNG engines — Xoshiro256**, RomuTrio, LCG64
  • Configurable streams — bounded-integer strategies, float precision, optional statistics
  • Forkable / restorable — child streams, snapshots, history stack
  • Rich statistics — continuous & discrete distributions, stochastic processes
  • Sampling toolkit — reservoir, stratified, systematic, Monte Carlo, importance sampling
  • Secure helpers — tokens, passwords, PBKDF2, HMAC via secrets
  • Zero dependencies —stdlib only

Installation

pip install rngpro

Development:

pip install -e ".[dev]"
pytest tests/ -v

Quick start

import rngpro

# Module-level shortcuts (default stream)
rngpro.default_rng(seed=42)
print(rngpro.randint(1, 6))
print(rngpro.uniform(0, 1))

# Explicit stream
rng = rngpro.RNG(seed=42, engine="xoshiro")
print(rng.random())
print(rng.gauss(0, 1))

# Custom "level" — any huge number fully seeds the stream
rng = rngpro.from_level(328734632476235423476)
rng = rngpro.RNG.from_level("328734632476235423476")

# Independent child stream
child = rng.fork(salt=1)

# Save / restore state
snap = rng.snapshot()
rng.restore(snap)
print(rng.report())

Package layout

rngpro/
├── __init__.py          # Public API + shortcuts
├── core/
│   ├── engines.py       # PRNG implementations & bit ops
│   ├── stream.py        # RNG class
│   ├── config.py        # StreamConfig, BoundedStrategy
│   └── registry.py      # EngineRegistry
├── stats/
│   ├── distributions.py # Dist sampler
│   ├── fitting.py       # DistributionFitter
│   └── sampling.py      # reservoir, monte_carlo, …
└── crypto/
    └── secure.py        # SecureRNG

Full API reference: docs/API.md


Engines

from rngpro import RNG, list_engines, get_registry

print(list_engines())  # ['lcg', 'romu', 'xoshiro']
print(get_registry().describe("xoshiro"))

rng = RNG(seed=0, engine="romu")
rng.jump()  # xoshiro only; romu/lcg use discard internally
Engine Best for
xoshiro Default — quality and speed
romu High-throughput simulation
lcg Minimal state, games/UI

Configuration

from rngpro import RNG, StreamConfig, BoundedStrategy, FloatPrecision

cfg = StreamConfig(
    bounded_strategy=BoundedStrategy.REJECTION,
    float_precision=FloatPrecision.BITS_53,
    enable_statistics=True,
    max_gauss_cache=1,
)
rng = RNG(seed=0, config=cfg)
rng.random()
print(rng.statistics.snapshot_dict())

Distributions

from rngpro import Dist, RNG

dist = Dist(RNG(seed=0))

samples = dist.normal(mu=0, sigma=1, n=10_000)
paths = dist.brownian(steps=252, sigma=0.2)
prices = dist.geometric_brownian(steps=252, s0=100)
times = dist.poisson_process(rate=1.5, horizon=10.0)

mean, var, std, lo, hi = dist.summary(samples)

Sampling & Monte Carlo

from rngpro import RNG
from rngpro.stats.sampling import (
    reservoir,
    monte_carlo_detailed,
    stratified,
    importance_sample,
)

rng = RNG(seed=1)
sample = reservoir(range(1_000_000), k=100, rng=rng)

result = monte_carlo_detailed(
    lambda x, y: 1.0 if x**2 + y**2 <= 1 else 0.0,
    [(-1, 1), (-1, 1)],
    samples=50_000,
    rng=rng,
)
print(result.estimate, result.stderr)  # ~π, stderr

Fitting & diagnostics

from rngpro.stats.fitting import DistributionFitter

fit = DistributionFitter()
data = [0.1, 0.5, 0.2, 0.9, 0.4]
mu, var = fit.mean_variance(data)
p50 = fit.percentile(data, 0.5)
jb = fit.jarque_bera(data)

Secure randomness

Never use PRNG output for passwords or keys.

from rngpro import SecureRNG, SecurityPolicy

token = SecureRNG.hex(32)
password = SecureRNG.password(length=20)
key = SecureRNG.derive_key("secret", SecureRNG.salt())

policy = SecurityPolicy(min_password_length=16, require_symbol=True)
Klass = SecureRNG.with_policy(policy)
strong = Klass.password()

Testing

The test suite covers engines, streams, registry, config, distributions, sampling, fitting, crypto, and the top-level API.

pytest tests/ -v --tb=short

License

MIT — Copyright (c) Frank Herniszis

Metadata

Release files for rngpro 2.7.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rngpro 2.7.6
File Size Uploaded Provenance Actions
rngpro-2.7.6.tar.gz 29.1 kB Without provenance Details for rngpro-2.7.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rngpro 2.7.6
File Interpreter ABI Platform Actions
rngpro-2.7.6-py3-none-any.whl Python 3 none any Details for rngpro-2.7.6-py3-none-any.whl

Total release size: 52.8 kB

Release files / rngpro-2.7.6.tar.gz

Download URL rngpro-2.7.6.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9bd38d538c3867106fc5f95f5415311293b48391928e03a7bd598acf4bc10493
BLAKE2b-256 checksum
How to use checksums
cd7435cfa71e12a9810bfb8a8f457339e77263cbd3729fd4df54c68ad92a3adf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / rngpro-2.7.6-py3-none-any.whl

Download URL rngpro-2.7.6-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4320572d65269e9da7c107b64ed10caa5f1059736b2e33e6f03b2cf96915825b
BLAKE2b-256 checksum
How to use checksums
8903374f326af03e17322eb1b378f0e6b4290bd6775eaea8090e8eae1f1df1ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for rngpro 2.7.6

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.

Release history Release notifications | RSS feed

This release

2.7.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page