Fast Random Number Generation

3.0.8 · active · verified Fri Apr 17

fastrand provides significantly faster random number generation in Python compared to the standard `random` module, implemented as a C extension. It is suitable for applications where speed is critical and cryptographic security is not required. The current version is 3.0.8, with a maintenance cadence of small patches and occasional feature additions.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import the fastrand module and use its primary functions: `pcg32bounded` for bounded integers, `pcg32` for unbounded 32-bit unsigned integers, and `randdouble` for floating-point numbers between 0 (inclusive) and 1 (exclusive).

import fastrand

print("Random integer [0, 99]:", fastrand.pcg32bounded(100))
print("Random 32-bit unsigned int:", fastrand.pcg32())
print("Random double [0, 1):")
for _ in range(3):
    print(f"  {fastrand.randdouble():.6f}")

view raw JSON →