getrandom

A small, cross-platform Rust crate for retrieving random bytes directly from the OS

Library
Cargo
v0.4.3
583 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 →
59 /100 Fair
Development Activity 60
Maintenance 12
Community 76
Maturity 60
Momentum 28

Technical Analysis

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

getrandom is a minimal-dependency Rust crate that provides a single, uniform interface for filling a buffer with random bytes sourced from the underlying operating system’s secure random number generator. It abstracts the differences between platform-specific APIs - getrandom(2)//dev/urandom on Linux, BCryptGenRandom on Windows, getentropy on macOS/BSD, and WASI/wasm-bindgen paths for WebAssembly - behind one getrandom::fill() call. Maintained by the Rand Project, it’s a foundational dependency underpinning much of the Rust cryptography and randomness ecosystem, including the rand crate itself.

What You Get

  • A single fill() function (plus a fallible try_fill() variant) that populates a byte slice with cryptographically secure random data from the OS
  • Platform backend implementations for Linux, Windows, macOS, the BSDs, WASI, and wasm32 targets (via an opt-in wasm_js feature) unified behind one public API
  • no_std compatibility, making it usable in embedded and other environments without the Rust standard library
  • An optional sys_rng feature exposing a SysRng type compatible with the rand_core traits for integration with the broader rand ecosystem
  • An Error type with no_std-friendly error codes plus an optional std-feature conversion to std::io::Error

Common Use Cases

  • Generating cryptographic key material, nonces, or salts that need to come directly from the OS’s secure randomness source rather than a userspace PRNG
  • Seeding a higher-level PRNG (such as those in the rand crate) with OS entropy at program startup
  • Sourcing random bytes in no_std or embedded Rust environments where the standard library isn’t available
  • Getting random bytes in a WebAssembly target, using the wasm_js feature to call into the browser’s crypto.getRandomValues under the hood

Under The Hood

Architecture The crate’s public surface lives almost entirely in the 159-line src/lib.rs, which declares the fill/try_fill functions and re-exports the Error type from src/error.rs; the actual platform dispatch happens in src/backends.rs, which uses cfg-if-driven conditional compilation to select the correct backend module (Linux’s getrandom(2) syscall, Windows’ BCryptGenRandom, macOS/BSD getentropy, WASI, or the optional wasm-bindgen path) at compile time rather than runtime, so there is zero dispatch overhead per call. src/sys_rng.rs layers an optional rand_core-compatible SysRng type on top of the same backend calls for crates that want to plug directly into the rand ecosystem’s trait hierarchy. build.rs handles target-specific build-time configuration (detecting libc features, WASM target variants) needed to pick the right backend at compile time. Tech Stack Pure Rust, edition 2024, with cfg-if as effectively the only unconditional dependency; wasm-bindgen/js-sys and rand_core are opt-in via Cargo features (wasm_js, sys_rng) rather than defaults, keeping the dependency footprint minimal for the common non-WASM case. The crate is no_std-compatible by default, with std gated behind an explicit feature flag. Code Quality The tests/ directory is small (2 files) since most of the real testing burden is platform-matrix CI rather than unit tests of pure logic — there’s little application logic to unit test beyond backend dispatch — supplemented by a separate custom_impl_test and nopanic_check crate in the repo root that verify the custom-backend override mechanism and confirm the fast path is panic-free. Given the crate’s small, security-sensitive surface, the low line count itself is a quality signal: less code means less to audit. API Design The API is deliberately reduced to essentially one call (getrandom::fill(&mut buf)), which is about as low-friction as a public API can get; the tradeoff is that feature flags (std, wasm_js, sys_rng) and backend-override mechanisms via getrandom_backend cfg require reading the docs for anything beyond the default case, which is appropriate for a foundational crate whose users are mostly other libraries rather than end applications.

Used by 17 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 4 days ago
TypeScript
80%
GPL 3.0

Bramble

Authentication · Password Manager · Security

399

Local-first, end-to-end encrypted password manager that syncs your vault directly between your own devices over a private peer-to-peer mesh — no server, no account, no cloud in the middle.

View details
75
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 80%
Updated 5 days 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 4 days ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
TypeScript
64%
Other

Epicenter

Developer Tools · Knowledge Management · Note Taking

4,808

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
88
Repo Health
90
Technical
64
Dependency
Built with
TypeScript 64%
HTML 13%
Svelte 13%
Updated 5 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
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

802

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
78
Repo Health
75
Technical
65
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 1 months ago
Rust
71%
Apache 2.0

mesh-llm

AI Agents · AI Development

3,463

Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.

View details
84
Repo Health
91
Technical
69
Dependency
Built with
Rust 71%
TypeScript 13%
Python 10%
Updated 4 days ago
TypeScript
88%
MIT

Mistle

AI Agents · Developer Tools

93

Self-hostable platform for running autonomous coding agents in isolated, credentialless sandboxes with brokered credentials, reusable snapshots, and event-driven triggers.

View details
68
Repo Health
76
Technical
70
Dependency
Built with
TypeScript 88%
Rust 11%
Updated 2 months 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