Expand description
Alea: A flexible random number generation library
This crate provides a modular and extensible framework for random number generation with multiple backend implementations. It allows users to choose different RNG algorithms while maintaining a consistent interface.
§Features
- Multiple RNG backend implementations
- Consistent interface across all backends
- Easy to extend with new backends
- Support for both integer and floating-point random numbers
§Examples
use alea::{Rng, backend::XorShift};
// Create a new RNG with the XorShift backend
let backend = XorShift::new(12345);
let mut rng = Rng::new(backend);
// Generate random numbers
let random_int = rng.next_u64();
let random_float = rng.next_f64();
§Available Backends
XorShift
: Fast and simple algorithmPCG
: High-quality permuted congruential generatorLCG
: Linear congruential generatorMT19937_64
: 64-bit Mersenne TwisterSplitMix64
: Fast, simple generator good for initializationXoshiro256StarStar
: Modern, high-quality generator
§Implementing Custom Backends
To implement a custom backend, implement the RandomBackend
trait:
use alea::RandomBackend;
struct MyBackend {
state: u64,
}
impl RandomBackend for MyBackend {
fn next_u64(&mut self) -> u64 {
// Your implementation here
self.state
}
}
Re-exports§
pub use backend::RandomBackend;
Modules§
- backend
- Random number generator backend implementations.
Structs§
- Rng
- A random number generator that works with any backend implementing
RandomBackend
.