rand

The de facto standard random number generation library for Rust.

Library
Cargo
v0.10.3
2,085 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
80 /100 Excellent
Development Activity 80
Maintenance 60
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
92 /100 Excellent
Architecture 92
Code Quality 93
Innovation 94
Learning Curve 85

Rand is a Rust library for random number generation, providing a trait-based foundation for pseudo-random and cryptographically-secure generators alongside a rich toolkit for sampling values, ranges, distributions, and sequences. Built on the rand_core RngCore trait, it ships fast, automatically-seeded generators such as ThreadRng and StdRng plus small PRNGs, and layers on ergonomic helpers like rand::random() and random_range().

It supports uniform and non-uniform distributions, weighted sampling, shuffling and choosing from slices, and portable reproducible output, with #[no_std] compatibility and optional Serde support. Rand is the most widely adopted randomness crate in the Rust ecosystem, downloaded well over a billion times.

What You Get

  • Automatically-seeded, reasonably strong generators (ThreadRng, StdRng) plus fast small PRNGs, all built over the rand_core RngCore trait
  • Uniform and ranged value sampling via StandardUniform and Uniform, plus a large set of non-uniform distributions
  • Sequence utilities for shuffling, choosing, and weighted selection from slices and iterators
  • no_std compatibility, optional Serde support, and portably reproducible output for deterministic use cases

Common Use Cases

  • Generating random numbers, booleans, and values of common types with a single rand::random() call
  • Sampling from a numeric range or a statistical distribution for simulations and Monte Carlo methods
  • Shuffling collections or picking random and weighted elements from slices in games, tests, and tooling

Under The Hood

Architecture

Rand is layered on top of the separate rand_core crate, which defines the RngCore, Rng, and SeedableRng traits re-exported from src/lib.rs. The crate is organized into focused modules: src/rngs/ supplies concrete generators (StdRng backed by ChaCha in std.rs, ThreadRng in thread.rs, SmallRng and the xoshiro128/256++ PRNGs), src/distr/ holds the sampling layer (StandardUniform, Uniform with per-type uniform_int/uniform_float back-ends, Bernoulli, and weighted indices), and src/seq/ implements sequence operations like shuffle and choose via a coin-flipper and increasing-uniform index sampler. Top-level convenience functions (rand::random, random_range, rng) in src/rng.rs and a prelude tie the layers together for ergonomic use.

Tech Stack

Written in Rust on the 2024 edition with an MSRV of 1.85, the crate is #[no_std] by default with alloc and std opt-in feature layers. Runtime dependencies are minimal: rand_core for the trait foundation, chacha20 for the cryptographic StdRng, and getrandom for OS entropy seeding, with serde available behind a feature. A granular feature matrix (std_rng, sys_rng, thread_rng, chacha, simd_support, unbiased) lets consumers trade functionality against footprint. Building and testing use standard Cargo, with dev-dependencies including rand_pcg, rayon, and serde_json.

Code Quality

Code quality is high and correctness-focused. The crate enforces #![deny(missing_docs)], missing_debug_implementations, and undocumented_unsafe_blocks, and carries roughly 107 unit-test functions across ~20 files plus integration tests (tests/fill.rs), doctests on public APIs, and a dedicated benches/ suite. A clippy.toml and CI workflows back consistent linting. Naming follows idiomatic Rust conventions and unsafe blocks are documented, reflecting the project’s stated priority of correctness and speed over simplicity.

API Design

The public API is deliberately ergonomic: newcomers can call rand::random() or rand::random_range(a..b) with zero setup, while power users compose over the Rng trait and explicit generators. A prelude module surfaces the common imports, distributions read fluently (Uniform::new, StandardUniform), and sequence helpers hang off iterator/slice extension traits. Documentation is exceptional, spanning inline docs enforced by deny(missing_docs), published docs.rs reference, and the dedicated Rust Rand Book with a quick-start guide, which keeps the learning curve manageable despite the domain’s inherent depth.

Used by 46 apps in this directory

TypeScript
54%
MIT

Anarlog

AI Assistants · Note Taking · Productivity

9,404

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript 54%
Rust 34%
Updated 5 days ago
Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 1 weeks ago
Rust
54%
Other

Cap

Team Chat · Video Conferencing

22,884

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust 54%
TypeScript 42%
Updated 5 days ago
Rust
52%
Apache 2.0

cocoindex

AI Development · Data Engineering

11,607

An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 52%
Python 48%
Updated 5 days ago
TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,049

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
73
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 6 days ago
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,787

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 75%
Updated 5 days ago
Rust
95%
MIT

Fyrox

Game Development

9,568

A production-ready 2D/3D game engine written in Rust with a built-in scene editor, physics, and hot-reloading game scripts

View details
85
Repo Health
79
Technical
68
Dependency
Built with
Rust 95%
Updated 6 days ago
Rust
52%
Other

hoodik

File Storage · Security

1,484

Self-hosted, end-to-end encrypted cloud storage with browser-based encryption and S3-compatible storage support

View details
79
Repo Health
71
Technical
63
Dependency
Built with
Rust 52%
TypeScript 33%
Vue 14%
Updated 1 weeks ago
Rust
37%
Other

Hook0

Devops

1,491

Open-source Webhooks-as-a-Service: deliver events to your users with auto-retry, signed payloads, and a real-time subscriber dashboard — all without building the infrastructure yourself.

View details
82
Repo Health
82
Technical
69
Dependency
Built with
Rust 37%
TypeScript 12%
Updated 1 weeks ago

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