skillfed

random2

Python 3 compatible Python 2 `random` Module.

random2 v1.0.2 171.2K downloads/30d#10,379 on PyPI
Permissive license Python 2.1.1 DORMANT released

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 random2

uv

uv add random2

poetry

poetry add random2

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Python Software Foundation LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: Implementation :: CPython

Tags

python 2 random module python 3reproducible random sequences cross-versionpython 2.7 random compatibilitystable random generator resultsrandrange python 2 behaviorseed-stable random numberspython version random compatibility
python-2-compatreproducibilitytesting

More Software Development packages