Randomgen
Numpy-compatible bit generators and add some random variate distributions missing from NumPy.
Install / Use
/learn @bashtage/RandomgenREADME
RandomGen
This package contains additional bit generators for NumPy's
Generator and an ExtendedGenerator exposing methods not in Generator.
Continuous Integration
Coverage
Latest Release
License
This is a library and generic interface for alternative random generators in Python and NumPy.
New Features
The the development documentation for the latest features, or the stable documentation for the latest released features.
WARNINGS
Changes in v1.24
Generator and RandomState were removed in 1.23.0.
Changes from 1.18 to 1.19
Generator and RandomState have been officially deprecated in 1.19, and will
warn with a FutureWarning about their removal. They will also receive virtually
no maintenance. It is now time to move to NumPy's np.random.Generator which has
features not in randomstate.Generator and is maintained more actively.
A few distributions that are not present in np.random.Generator have been moved
to randomstate.ExtendedGenerator:
multivariate_normal: which supports broadcastinguintegers: fast 32 and 64-bit uniform integerscomplex_normal: scalar complex normals
There are no plans to remove any of the bit generators, e.g., AESCounter,
ThreeFry, or PCG64.
Changes from 1.16 to 1.18
There are many changes between v1.16.x and v1.18.x. These reflect API
decision taken in conjunction with NumPy in preparation of the core
of randomgen being used as the preferred random number generator in
NumPy. These all issue DeprecationWarnings except for BasicRNG.generator
which raises NotImplementedError. The C-API has also changed to reflect
the preferred naming the underlying Pseudo-RNGs, which are now known as
bit generators (or BigGenerators).
Future Plans
- Add some distributions that are not supported in NumPy. Ongoing
- Add any interesting bit generators I come across. Recent additions include the DXSM and CM-DXSM variants of PCG64 and the LXM generator.
Included Pseudo Random Number Generators
This module includes a number of alternative random number generators in addition to the MT19937 that is included in NumPy. The RNGs include:
- Cryptographic cipher-based random number generator based on AES, ChaCha20, HC128 and Speck128.
- MT19937, the NumPy rng
- dSFMT a SSE2-aware version of the MT19937 generator that is especially fast at generating doubles
- xoroshiro128+, xorshift1024*φ, xoshiro256**, and xoshiro512**
- PCG64
- ThreeFry and Philox from Random123
- Other cryptographic-based generators:
AESCounter,SPECK128,ChaCha, andHC128. - Hardware (non-reproducible) random number generator on AMD64 using
RDRAND. - Chaotic PRNGS: Small-Fast Chaotic (
SFC64) and Jenkin's Small-Fast (JSF).
Status
- Builds and passes all tests on:
- Linux 32/64 bit, Python 3.7, 3.8, 3.9, 3.10
- Linux (ARM/ARM64), Python 3.8
- OSX 64-bit, Python 3.9
- Windows 32/64 bit, Python 3.7, 3.8, 3.9, 3.10
- FreeBSD 64-bit
Version
The package version matches the latest version of NumPy when the package is released.
Documentation
Documentation for the latest release is available on my GitHub pages. Documentation for the latest commit (unreleased) is available under devel.
Requirements
Building requires:
- Python (3.9, 3.10, 3.11, 3.12, 3.13)
- NumPy (1.22.3+, runtime, 2.0.0+, building)
- Cython (3.0.10+)
Testing requires pytest (7+).
Note: it might work with other versions but only tested with these versions.
Development and Testing
All development has been on 64-bit Linux, and it is regularly tested on Azure (Linux-AMD64, Window, and OSX) and Cirrus (FreeBSD and Linux-ARM).
Tests are in place for all RNGs. The MT19937 is tested against NumPy's implementation for identical results. It also passes NumPy's test suite where still relevant.
Installing
Either install from PyPi using
python -m pip install randomgen
or, if you want the latest version,
python -m pip install git+https://github.com/bashtage/randomgen.git
or from a cloned repo,
python -m pip install .
If you use conda, you can install using conda forge
conda install -c conda-forge randomgen
SSE2
dSFTM makes use of SSE2 by default. If you have a very old computer
or are building on non-x86, you can install using:
export RANDOMGEN_NO_SSE2=1
python -m pip install .
Windows
Either use a binary installer, or if building from scratch, use Python 3.6/3.7 with Visual Studio 2015 Build Toolx.
License
Dual: BSD 3-Clause and NCSA, plus sub licenses for components.
Related Skills
claude-opus-4-5-migration
83.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
339.3kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
49.9k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.7kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
