What it does
Random number generation in Rust today forces a choice: pull in the
heavy rand ecosystem (multiple crates, opinionated traits, generic
overhead) or write your own. mod-rand is the middle ground — three
clearly-tiered random sources in one library, zero external
dependencies, MSRV 1.75.
The three tiers
use ;
// Tier 1: Fast deterministic PRNG — for simulations and test fixtures.
let mut rng = seed_from_u64;
let n: u64 = rng.next_u64;
// Tier 2: Process-unique seeds — for tempdir names and request IDs.
let name: String = unique_name;
// Tier 3: Cryptographic random — for tokens and keys.
let token: String = random_hex?;
# Ok::
| Tier | Algorithm | Use case | Crypto-safe |
|---|---|---|---|
| 1 | xoshiro256** | Simulation, fixtures, shuffling | No |
| 2 | PID + nanos + counter mix | Tempdir names, request IDs | No |
| 3 | OS syscall (getrandom/BCryptGenRandom/getentropy) |
Tokens, keys, session IDs | Yes |
Why this library exists
- Zero dependencies. No
rand, nogetrandomcrate, nolibc. Juststd. Tier 1 even works inno_std. - Explicit threat model. You pick the tier; you know what guarantees you're getting.
- Lower MSRV than the alternatives. Works on Rust 1.75; many random crates today require 1.85+.
- Fast. Tier 1 is ~1ns/u64. Tier 2 is ~50ns. Tier 3 is one syscall.
Feature flags
[]
= { = "0.1", = false } # tier1 only, no_std
= { = "0.1", = ["tier2"] } # + process-unique
= "0.1" # all three tiers (default)
Status
v0.1.0 is the name-claim release with placeholder implementations.
Real algorithms (full xoshiro256**, splitmix64 seeding, platform
syscalls) land in 0.9.x. Do not use the cryptographic tier from
v0.1.0 for security-sensitive work — the placeholder is not
cryptographically secure.
Minimum supported Rust version
1.75 — pinned in Cargo.toml and verified by CI.
License
Apache-2.0. See LICENSE.