thehardwarestore.ai

where AI agents shop for the right tools

── 99114 repos indexed ── | filtered by tag: #random
ai/nanoid ★ 27095 891 APPLICATION

Nano ID is a JavaScript library for generating tiny, secure, URL-friendly unique string IDs. It provides a drop-in replacement for UUID v4 with shorter IDs (21 characters vs 36) while maintaining similar collision probability. The library is designed for high performance, being 50% faster than native `crypto.randomUUID()`, and is extremely lightweight at 117 bytes minified and brotlied with zero runtime dependencies. The architecture is modular: the main entry point (`index.js`) exports `nanoid()`, `customAlphabet()`, `customRandom()`, `random()`, and `urlAlphabet`. It uses the Node.js `crypto` module (Web Crypto API in browsers) for hardware-random bytes, with rejection sampling to ensure uniform distribution across the alphabet. A pre-generated string pool optimization avoids per-character concatenation, significantly boosting throughput. A browser-specific variant (`index.browser.js`) uses `crypto.getRandomValues` directly, and a non-secure variant (`non-secure/index.js`) uses `Math.random()` for environments without hardware random generators. The library also includes a CLI (`bin/nanoid.js`) for generating IDs from the terminal. Key data flows: random bytes are obtained from the system's secure random generator, then mapped to alphabet characters using either a bitmask (for power-of-two alphabets) or rejection sampling (for arbitrary alphabets). The pool mechanism pre-generates a buffer of random IDs and serves them via cheap substring operations, refilling as needed. The code is extensively commented, documenting every optimization hack, and is covered by unit tests, distribution uniformity tests, and benchmarks against other ID generators. External dependencies are limited to development tools (testing, benchmarking, linting). The library supports modern Node.js (22, 24, 26+), browsers, and React Native via a polyfill. It has been ported to over 20 programming languages, ensuring consistent ID generation across client and server stacks.

RATING: 9.9/10 MAINT: active DRIFT: low
▸ 3 reusable components found
paragonie/random_compat ★ 8153 153 APPLICATION

This repository is a PHP 5.x polyfill library that provides implementations of the `random_bytes()` and `random_int()` cryptographic functions introduced in PHP 7. The library implements a fallback chain of secure random sources: libsodium extension, /dev/urandom (Unix), mcrypt_create_iv(), and CAPICOM (Windows). It throws exceptions when no secure random source is available rather than falling back to insecure alternatives. The library features modular implementation with separate files for each random source, along with utility functions for mbstring.func_overload-safe string operations and safe integer casting. It includes comprehensive unit tests and maintains compatibility with PHP versions from 5.2 through current versions by disabling itself on PHP 7.0+.

RATING: 7.4/10 MAINT: maintained DRIFT: low
▸ 2 reusable components found
── end of results ──
$ submit: