Random Access RNG
A fast, deterministic random number generator with hierarchical seeding and random access capabilities.
Features
- 🚀 Fast: Uses XXH3 hash function for high performance
- 🎯 Deterministic: Same seed always produces the same sequence
- 🌳 Hierarchical: Create child RNGs with different seeds
- 📍 Random Access: Jump to any position without generating intermediate values
- 🛤️ Path-based: Use paths to create RNG hierarchies
- 🔧 Standard Compatible: Implements RngCore and SeedableRng traits
Quick Start
Add to your Cargo.toml
:
[]
= "0.1.0"
Basic usage:
use RandomAccessRNG;
// Create a new RNG with a seed
let mut rng = new;
// Generate random numbers
let value = rng.next_u64;
// Create child RNGs
let child = rng.get;
// Use path-based seeding
let path_rng = rng.path;
Examples
Procedural Terrain Generation
use RandomAccessRNG;
use Rng;
// Generate terrain for different coordinates
let height1 = generate_terrain;
let height2 = generate_terrain; // Same result
let height3 = generate_terrain; // Different result
Game Development
use RandomAccessRNG;
let world = new;
let enemy = world.generate_enemy;
let item = world.generate_item;
Key Concepts
Deterministic Randomness
The same seed always produces the same sequence, making it perfect for:
- Procedural generation
- Reproducible simulations
- Testing and debugging
let mut rng1 = new;
let mut rng2 = new;
// Both RNGs produce identical sequences
assert_eq!;
assert_eq!;
Hierarchical Seeding
Create independent child RNGs that maintain deterministic properties:
let parent = new;
// Different aspects can have their own RNGs
let terrain_rng = parent.get;
let enemy_rng = parent.get;
let item_rng = parent.get;
// Each child RNG is independent and deterministic
Random Access
Jump to any position in the sequence instantly:
let mut rng = new;
// Jump directly to position 1000
let value_at_1000 = rng.seek_u64;
// Jump to position 5000
let value_at_5000 = rng.seek_u64;
// Jump to back position 0
let value_at_5000 = rng.seek_u64;
Path-Based Seeding
Use file system-like paths to create RNG hierarchies:
let world = new;
// Create RNGs for specific locations
let forest_rng = world.path;
let cave_rng = world.path;
let village_rng = world.path;
Performance
This RNG is designed for speed and uses the XXH3 hash function, which is:
- Extremely fast
- High quality for non-cryptographic purposes
- Well-distributed output
Security Notice
This RNG is NOT cryptographically secure. It's designed for:
- Procedural generation
- Simulation and testing
- Game development
- Any application requiring deterministic randomness
For security-sensitive applications, use a cryptographically secure RNG marked by the CryptoRng trait.
Installation
Add to your Cargo.toml
:
[]
= "0.1.0"
Documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
0.1.0
- Initial release
- Basic RNG functionality
- Hierarchical seeding
- Random access capabilities
- Path-based seeding