fastrand

A simple and fast non-cryptographic random number generator for Rust

Library
Cargo
v2.5.0
601stars
Apache-2.0 OR MIT

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
52/100Fair
Development Activity44
Maintenance28
Community48
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture80
Code Quality84
Innovation70
Learning Curve90

fastrand is a simple, fast random number generator for Rust built on the Wyrand algorithm. It exposes a small set of free functions for generating booleans, integers over ranges, floats, and characters, along with helpers to shuffle slices, choose random elements, and sample multiple values.

By default it uses a convenient thread-local generator, but you can also create dedicated Rng instances for more control and better performance in hot loops, and seed the generator for reproducible results. It is deliberately not cryptographically secure, trading security for speed and a minimal, dependency-light API that works on no_std targets.

What You Get

  • Free functions for bool, ranged integers (i32, usize, etc.), floats, and characters
  • Slice helpers: shuffle, choose_multiple, and random element selection
  • A thread-local generator plus standalone Rng instances for hot paths
  • Seeding for reproducible sequences and no_std support

Common Use Cases

  • Picking random elements, shuffling collections, or generating test data
  • Fast random sampling in simulations, games, and procedural generation
  • Seeded, reproducible randomness for deterministic tests

Under The Hood

Architecture - The crate splits into two modules: src/lib.rs (~736 lines) defines the Rng struct and its methods for generating typed values over ranges, floats, characters, shuffling, and sampling, all driven by the Wyrand algorithm (a multiply-and-mix step over a 64-bit state). src/global_rng.rs wraps an Rng in a thread-local and re-exports the same operations as free functions plus a seed entry point, so callers can use either the ergonomic global API or their own instances.

Tech Stack - Pure Rust (edition 2018), non-cryptographic by design. Optional features add std-backed thread-local seeding and js support for Wasm targets; the core builds on no_std. No heavy runtime dependencies.

Code Quality - Compact and well-tested with a mature history (hundreds of millions of downloads). Range generation uses standard bias-reduction techniques, and the two-module split keeps the generator logic separate from the global convenience layer.

API Design - Extremely approachable: functions like fastrand::bool(), fastrand::i32(..), fastrand::shuffle(&mut v), and fastrand::choose_multiple(…) read naturally and require no setup. Switching from the global generator to a dedicated Rng instance is a one-line change, giving a very gentle learning curve.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search