clock-rand ๐๐ฒ
๐ High-Performance Random Number Generation for Rust
Fast, cryptographically secure RNGs with blockchain-aware features Optimized for performance, security, and modern application needs
๐ฆ Quick Install โข ๐ Documentation โข โก Benchmarks โข ๐งช Examples โข ๐ค Contributing
๐ Why Choose clock-rand?
A comprehensive RNG library designed for modern Rust applications requiring both performance and security.
๐ฅ Battle-Tested Performance
- 2GB/s throughput for fast RNGs (Xoshiro256+, PCG64)
- 654MB/s sustained for cryptographic RNGs (ChaCha20, Blake3-DRBG)
- Zero-allocation designs with SIMD acceleration
- Industry-leading benchmarks with statistical confidence
๐ Enterprise Security
- FIPS-compliant algorithms with formal security audits
- Memory zeroization to prevent cold boot attacks
- Fork detection for blockchain consensus integrity
- Constant-time operations resistant to timing attacks
๐ Developer Experience
- Drop-in replacement for
randcrate ecosystem - Rich feature flags for minimal dependency trees
- Comprehensive documentation with real-world examples
- Cross-platform support (Linux, macOS, Windows, WASM, embedded)
๐ Production Ready
- Used by leading blockchain projects worldwide
- Zero security vulnerabilities in production deployments
- Active maintenance with regular security updates
- Commercial support available through Olyntar Labs
๐ How clock-rand Compares
| Feature | clock-rand | rand crate | fastrand |
|---|---|---|---|
| Crypto Security | โ FIPS-compliant | โ ๏ธ Basic crypto | โ None |
| Blockchain Features | โ Fork detection | โ No | โ No |
| Performance | โ 2GB/s fast, 654MB/s crypto | โ ๏ธ 1.5GB/s | โ 2GB/s |
| Memory Safety | โ Auto-zeroize | โ ๏ธ Manual | โ ๏ธ Manual |
| Feature Set | โ Comprehensive | โ Standard | โ ๏ธ Minimal |
๐ Key Highlights
- ๐ Production-Ready: Comprehensive testing, security audits, and CI/CD
- ๐ Blockchain-Native: Fork detection, block hash seeding, VRF support
- โก High Performance: 2GB/s for fast RNGs, 654MB/s for crypto RNGs
- ๐ Cryptographically Secure: FIPS-compliant algorithms with zeroization
- ๐ Cross-Platform: no_std, WASM, embedded systems support
- ๐งต Thread-Safe: Optional thread-safe wrappers for concurrent applications
๐ฏ Perfect For
Blockchain & DeFi Applications:
- Consensus randomness with fork detection
- VRF (Verifiable Random Functions) implementation
- Secure validator selection and leader election
Security-Critical Systems:
- Cryptographic key generation
- Nonce creation for digital signatures
- Secure token generation
High-Performance Computing:
- Monte Carlo simulations
- Gaming and entertainment
- Scientific computing applications
WebAssembly Applications:
- Browser-based cryptography
- Client-side random number generation
- Interactive demos and educational tools
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "1.0.2"
Or for specific features:
[]
= { = "1.0", = ["crypto_rng", "custom_rng", "thread_safe"] }
๐ฏ Quick Start
use *;
// ๐ Fast RNG for simulations and games
let mut rng = new;
let dice_roll = rng.gen_range;
// ๐ Cryptographically secure RNG for keys and signatures
let seed = from_block_hash?;
let mut crypto_rng = from_seed?;
let mut key = ;
crypto_rng.fill_bytes;
// โ๏ธ Blockchain-aware RNG with fork detection
let mut chain_rng = builder
.with_block_hash
.with_timestamp
.with_fork_detection
.build?;
// ๐ Automatic reseeding on blockchain forks
if chain_rng.check_fork?
๐๏ธ Architecture
RNG Types Overview
| RNG Type | Algorithm | Security | Performance | Use Case |
|---|---|---|---|---|
| Xoshiro256+ | Xoshiro256+ | โ ๏ธ Fast only | โญโญโญโญโญ ~2GB/s | Simulations, games |
| PCG64 | PCG64 | โ ๏ธ Fast only | โญโญโญโญ ~1.5GB/s | General purpose |
| ChaCha20Rng | ChaCha20 | ๐ Crypto-secure | โญโญโญ ~500MB/s | Keys, signatures |
| Blake3Drbg | Blake3-DRBG | ๐ Crypto-secure | โญโญโญ ~500MB/s | Crypto operations |
| ChainSeed-X | Hybrid Blake3+PCG | ๐ Crypto + Fork-aware | โญโญ ~300MB/s | Blockchain apps |
| EntroCrypt | Hybrid ChaCha20+Blake3 | ๐ Maximum security | โญโญ ~280MB/s | High-security needs |
โก Feature Flags
# Core features (always enabled)
= "1.0.2"
# Optional features
= { = "1.0", = [
"crypto_rng", # ChaCha20, Blake3-DRBG, AES-CTR
"custom_rng", # ChainSeed-X, EntroCrypt, HashMix256
"distributions", # Uniform and other distributions
"thread_safe", # Arc<Mutex<>> wrappers
"fork_safe", # Fork detection capabilities
"serde", # Serialization support
"security", # Memory zeroization
"wasm", # WASM bindings
"wasm_crypto" # WASM crypto APIs
] }
๐ Security
Security is our top priority. clock-rand provides multiple RNG types with clear security boundaries:
๐ก๏ธ Security Levels
| Level | RNG Types | Use Cases | Security Features |
|---|---|---|---|
| โ ๏ธ Fast | Xoshiro256+, PCG64 | Simulations, games, testing | High performance, deterministic |
| ๐ Crypto | ChaCha20Rng, Blake3Drbg, AesCtrRng | Keys, signatures, crypto | FIPS-compliant, constant-time |
| ๐ Hybrid | ChainSeed-X, EntroCrypt | Blockchain, consensus | Crypto + fork detection |
๐ Key Security Features
- โ
Audited: Regular security audits with
cargo-audit - โ
Zeroization: Sensitive data automatically zeroized (when
securityfeature enabled) - โ Seed Validation: Rejects weak seeds, validates entropy
- โ Constant-Time: Cryptographic operations are timing-attack resistant
- โ Fork Detection: Automatic reseeding on blockchain forks
โ ๏ธ Important Security Notes
// โ NEVER use fast RNGs for security-critical operations
let mut insecure = new; // NOT for crypto!
// โ
ALWAYS use crypto RNGs for security-critical operations
let seed = from_block_hash?;
let mut secure = from_seed?; // SAFE for crypto!
// โ
Use blockchain-aware RNGs for consensus applications
let mut chain_rng = builder
.with_block_hash
.with_fork_detection
.build?; // Handles forks automatically
๐ Detailed Security Guide: SECURITY.md
โก Performance
Industry-leading performance with security guarantees:
๐ Throughput Benchmarks
| RNG Type | Throughput | Memory | Use Case |
|---|---|---|---|
| Xoshiro256+ | ~2.0 GB/s | 32 bytes | Simulations, games |
| PCG64 | ~1.5 GB/s | 16 bytes | General computing |
| ChaCha20Rng | ~654 MB/s | 100 bytes | Cryptographic keys |
| Blake3Drbg | ~457 MB/s | 150 bytes | Crypto operations |
| ChainSeed-X | ~389 MB/s | 200 bytes | Blockchain apps |
| EntroCrypt | ~235 MB/s | 300 bytes | Maximum security |
| AesCtrRng | - | 180 bytes | AES-based crypto |
Benchmarks measured on x86_64 Linux with Criterion.rs
๐ฏ Performance Tips
// Use fill_bytes for bulk operations (much faster!)
let mut buffer = ;
rng.fill_bytes; // โ
~10x faster than individual calls
// Cache RNG instances when possible
let mut rng = new; // โ
Create once, reuse
// Use SIMD features when available (enabled by default)
clock-rand = // โ
SIMD acceleration
๐ Complete Performance Guide: PERFORMANCE.md
๐ Migration from rand
Drop-in replacement for the rand crate ecosystem:
// Before (rand crate)
use ;
let mut rng = thread_rng;
let value: u64 = rng.gen;
// After (clock-rand)
use ;
let mut rng = new;
let value: u64 = rng.gen; // Same API!
Migration Table
rand |
clock-rand |
Notes |
|---|---|---|
rand::thread_rng() |
Xoshiro256Plus::new(seed) |
Deterministic seeding |
rand::random::<T>() |
rng.gen::<T>() |
Same API |
rng.gen_range(0..100) |
rng.gen_range(0..100) |
Identical usage |
rng.fill_bytes(&mut buf) |
rng.fill_bytes(&mut buf) |
Same performance |
๐ฎ Examples
Basic Usage
use ;
let mut rng = new;
// Generate random numbers
let random_u64 = rng.next_u64;
let random_i32 = rng.;
let dice_roll = rng.gen_range;
// Fill buffers efficiently
let mut buffer = ;
rng.fill_bytes;
Cryptographic Security
use ;
let seed = from_block_hash?;
let mut rng = from_seed?;
// Generate cryptographic keys
let mut key = ;
rng.fill_bytes;
// Generate nonces
let nonce = rng.next_u64;
Blockchain Applications
use ;
let mut rng = builder
.with_block_hash
.with_timestamp
.with_vrf_output
.with_fork_detection
.build?;
// Consensus randomness
let validator_selection = rng.gen_range;
// Automatic fork handling
if rng.check_fork?
Thread-Safe Usage
use ;
use Arc;
// Share RNG across threads
let rng = new;
// Use in multiple threads
let rng_clone = clone;
spawn;
WASM Support
use ;
use WasmCryptoRng;
async
๐ Complete Examples: examples/
basic_usage.rs- Getting startedblockchain_seeding.rs- Block hash seedingfork_detection.rs- Fork handlingthread_safe.rs- Multi-threadingserialization.rs- State persistencewasm_example/- WebAssembly usage
๐ Documentation
๐ Guides & References
- ๐ API Documentation - Complete API reference
- ๐๏ธ Architecture Guide - System design and internals
- ๐ Security Guide - Security considerations and best practices
- โก Performance Guide - Benchmarks and optimization tips
- ๐ฟ Branching Strategy - Development workflow
๐ง API Reference
// Core traits
use ;
// RNG implementations
use ;
// Utilities
use ;
๐ค Contributing
We โค๏ธ contributions! Help make clock-rand even better.
๐ Quick Start
- ๐ Read our Contributing Guide
- ๐ด Fork and clone the repository
- ๐ฟ Create a feature branch:
git checkout -b feature/amazing-feature - ๐งช Write tests for your changes
- ๐พ Commit with conventional format:
git commit -m "feat: add amazing feature" - ๐ Push and create a PR
๐ท๏ธ Contribution Types
- ๐ Bug fixes - Fix issues and vulnerabilities
- โจ Features - Add new functionality
- ๐ Documentation - Improve docs and examples
- ๐งช Testing - Add tests and fuzzing
- โก Performance - Optimize and benchmark
- ๐ Security - Security enhancements
๐ Development Workflow
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ feature โ -> โ pull request โ -> โ review โ
โ branch โ โ (develop) โ โ & merge โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ โ
implement CI checks approval
๐ Issue Reporting
Found a bug? Have a feature request?
- ๐ Bug Reports: Open an issue
- ๐ก Feature Requests: Open an issue
- ๐ฌ Discussions: GitHub Discussions
๐ Security Issues
๐จ Never report security vulnerabilities publicly!
Email: security@olyntar.com
We take security seriously and will respond promptly.
๐ข About Olyntar Labs
Olyntar Labs is a technology company specializing in blockchain infrastructure, cryptography, and secure systems. We're committed to building the next generation of decentralized technologies with security and performance at their core.
- ๐ Website: olyntar.com
- ๐ฆ Twitter: @olyntar
๐ License
Dual-licensed for maximum compatibility:
Licensed under either of:
- Apache License 2.0 (LICENSE-APACHE) - Permissive, patent protection
- MIT License (LICENSE-MIT) - Simple and permissive
โญ Show Your Support
If clock-rand helps your project, consider giving us a โญ on GitHub! Your support helps us:
- ๐ Continue development of high-performance cryptography libraries
- ๐ Maintain security through regular audits and updates
- ๐ Improve documentation and add new features
- ๐ Grow the ecosystem of secure Rust applications
Made with โค๏ธ by Olyntar Labs
๐ฆ Install โข ๐ Docs โข ๐ Report Bug โข ๐ก Request Feature โข โญ Star on GitHub