Hasty Briefsbeta

Bilingual

Why Casper forked Rust's rand crate

5 hours ago
  • The author forked Rust's 'rand' crate to create 'urandom', aiming to reduce papercuts and improve discoverability of everyday operations.
  • 'urandom' places the high-level consumer API on a single 'Random' wrapper struct, eliminating the need to import multiple traits for common operations like random range, choose, and shuffle.
  • 'urandom' seals its low-level 'Rng' trait, preventing external generators and allowing the crate to optimize algorithms (e.g., Xoshiro) for specific outputs like f32 and f64, achieving up to 31% higher throughput in benchmarks.
  • Uniform sampling in 'urandom' uses a unified, unbiased lazy threshold calculation, which is simpler and often faster than 'rand's split approach with separate biased and unbiased paths.
  • 'urandom' guarantees reproducibility of deterministic generators across architectures and SemVer-compatible releases, unlike 'rand' which may change output in minor updates.
  • The trade-off for 'urandom' is less flexibility (no arbitrary generators) and a smaller ecosystem compared to 'rand', but it offers improved performance and ease of use for common tasks.

Related

Loading…