getrandom
A small, cross-platform Rust crate for retrieving random bytes directly from the OS
Repository Health
Technical Analysis
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 fallibletry_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_jsfeature) unified behind one public API no_stdcompatibility, making it usable in embedded and other environments without the Rust standard library- An optional
sys_rngfeature exposing aSysRngtype compatible with therand_coretraits for integration with the broaderrandecosystem - An
Errortype withno_std-friendly error codes plus an optionalstd-feature conversion tostd::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
randcrate) with OS entropy at program startup - Sourcing random bytes in
no_stdor embedded Rust environments where the standard library isn’t available - Getting random bytes in a WebAssembly target, using the
wasm_jsfeature to call into the browser’scrypto.getRandomValuesunder 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
obscura
AI Agents · Developer Tools
A lightweight, stealthy headless browser written in Rust — drop-in compatible with Puppeteer and Playwright, built for AI agents and web scraping at scale.
OpenClaw
AI Agents · AI Assistants
An open-source AI assistant that runs on your own hardware and meets you in Discord, Slack, WhatsApp, iMessage, Telegram, and 20+ other channels, with native apps for every major platform.
OpenViking
AI Development · AI Memory · Databases
An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.
Rivet
AI Agents · Developer Tools
Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.
Shadowbroker
Analytics · Monitoring · Security
Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
VoiceStudio
Mcp · Music Audio · Voice AI
Open-source, fully local ElevenLabs alternative for voice cloning, voice design, video dubbing, dictation, transcription and audiobooks, with a local API and MCP server for agents.
World Monitor
Analytics · Monitoring
Real-time global intelligence dashboard that fuses AI-synthesized news, geopolitical risk scoring, and infrastructure tracking into one open-source situational awareness platform.