fastrand
A simple and fast non-cryptographic random number generator for Rust
Repository Health
Technical Analysis
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.
Used by 2 apps in this directory
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
Svix
Developer Tools · Automation
Open source, self-hostable webhook infrastructure that handles delivery, retries, HMAC signing, and multi-tenant event management so you never have to build a webhooks system from scratch.