random2
Python 3 compatible Python 2 `random` Module.
What it is and what it does
Random2 is a backport of Python 2.7's random module to Python 3. It exists to solve a specific compatibility problem: Python 3 changed the implementation of randrange(), so even with an identical seed, Python 2 and Python 3 produce different random sequences. This breaks reproducibility in test suites and other code that depends on stable, predictable random output across Python versions.
The package provides a drop-in replacement that generates the same sequence as Python 2.7 when given the same seed. It has no external dependencies and installs as a pure Python wheel. It is most useful for porting legacy test code or simulations from Python 2 to Python 3 without having to rewrite all the expected random outputs.
Use it for:
- Porting Python 2 test suites to Python 3 while keeping random-number expectations unchanged.
- Running stochastic simulations or Monte Carlo code that was originally written for Python 2 and requires identical results.
- Comparing random-number behavior between Python 2 and Python 3 implementations of the same algorithm.
- Reproducing historical results from Python 2 code that relied on specific random sequences.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python 2.7's random module implementation for Python 3, ensuring identical random sequences when using the same seed across Python versions.
Yes, if you are porting Python 2 code to Python 3 and need deterministic random sequences to remain stable. No, if you are writing new Python 3 code—use the native random module instead. The package is dormant but stable, carries no known vulnerabilities, and has minimal friction. It solves a narrow, real problem for legacy code migration.
Install
random2 on PyPI
pip
pip install random2uv
uv add random2poetry
poetry add random2Installing random2
Before you install
Low install friction with no runtime dependencies. Dormant maintenance status (970 days since last release) but marked Production/Stable and updated to support Python 3.10, 3.11, 3.12, and 3.13 as of 2023-12-18.
License in practice
Licensed under Python Software Foundation License (permissive), imposing no significant restrictions on use or redistribution.
Quickstart
pip install random2
import random2
random2.seed(0)
print(random2.randint(1, 10))
Requires Python 3.10, 3.11, 3.12, or 3.13; earlier Python 3 versions are not supported by version 1.0.2.
Verify before relying
- Whether the Python 2.7 random algorithm implementation is mathematically identical to the original or only functionally equivalent for typical use cases.
- Performance characteristics compared to Python 3's native random module.
- Specific numeric output examples to verify seed reproducibility across Python versions.
Package facts
| License | Python 2.1.1 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 970 days since the last release |
| First released | |
| Downloads | 171,150/month — #10,379 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: random2-1.0.2-py3-none-any.whl
Keywords: roman
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
pytest-rngProvides pytest fixtures that make random…
permissive · top 15,000 on PyPI
random-slugsGenerates random word-based slugs with…
unclear · top 15,000 on PyPI
pytest-randomlyA pytest plugin that randomly shuffles test…
permissive · top 5,000 on PyPI
pytorch-seedProvides reproducible random number generation…
permissive · top 15,000 on PyPI
haikunatorGenerates random Heroku-style names composed of…
permissive · top 15,000 on PyPI
pytest-random-orderA pytest plugin that randomizes the order in…
permissive · top 5,000 on PyPI
backports.csvProvides Python 3's csv module API for Python…
unclear · top 15,000 on PyPI
random-addressGenerates random real US addresses with…
permissive · top 15,000 on PyPI
dict-hashGenerates consistent hashes for Python…
permissive · top 15,000 on PyPI
pyudorandomGenerates pseudorandom numbers using algebraic…
unclear · top 15,000 on PyPI