1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Random number generator backend implementations.
//!
//! This module defines the core RNG backend trait [`RandomBackend`] and re-exports
//! a set of concrete algorithms. Each backend is small, dependency-free, and focuses
//! on clarity and correctness. These are not cryptographic RNGs.
//!
//! Highlights:
//! - Minimal trait surface with sensible defaults: `next_u64`, `next_u32`, `next_f64`, `fill_bytes`
//! - Multiple algorithms with different trade-offs (speed, state size, quality)
//! - Designed to be used through the high-level [`crate::Rng`] wrapper
//!
//! This module provides various random number generator (RNG) implementations with different
//! characteristics and trade-offs. Each backend implements the [`RandomBackend`] trait,
//! allowing them to be used interchangeably.
//!
//! # Available Backends
//!
//! - [`LCG`]: Linear Congruential Generator - Simple and fast, but with known limitations
//! - [`PCG`]: Permuted Congruential Generator - High-quality output with good statistical properties
//! - [`XorShift`]: Simple and fast algorithm with reasonable quality
//! - [`MT19937_64`]: 64-bit Mersenne Twister - Large state, very long period (2^19937-1)
//! - [`SplitMix64`]: Fast, simple generator suitable for initialization
//! - [`Xoshiro256StarStar`]: Modern, high-quality generator with excellent statistical properties
//!
//! # Choosing a Backend
//!
//! Each backend has different characteristics:
//!
//! | Backend | State Size | Speed | Quality | Period |
//! |---------|------------|-------|---------|---------|
//! | LCG | 8 bytes | Very Fast | Basic | 2^64 |
//! | PCG | 16 bytes | Fast | High | 2^64 |
//! | XorShift | 8 bytes | Very Fast | Good | 2^64 - 1 |
//! | MT19937_64 | 2.5KB | Moderate | High | 2^19937 - 1 |
//! | SplitMix64 | 8 bytes | Very Fast | Good | 2^64 |
//! | Xoshiro256** | 32 bytes | Very Fast | Excellent | 2^256 - 1 |
//!
//! # Examples
//!
//! ```rust
//! use aporia::{Rng, backend::XorShift};
//!
//! // Create a new RNG with 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();
//! ```
// Re-export all backends
pub use LCG;
pub use PCG;
pub use XorShift;
pub use MT19937_64;
pub use SplitMix64;
pub use Xoshiro256StarStar;
/// Trait that defines the interface for random number generator backends.
///
/// This trait must be implemented by all RNG backends. It provides a minimal
/// interface for generating random numbers, with a default implementation
/// for floating-point numbers.
///
/// # Required Methods
///
/// - `next_u64`: Generate the next 64-bit random integer
///
/// # Provided Methods
///
/// - `next_f64`: Generate a random float in [0, 1) using `next_u64`
///
/// # Examples
///
/// ```rust
/// use aporia::RandomBackend;
///
/// struct MyBackend {
/// state: u64
/// }
///
/// impl RandomBackend for MyBackend {
/// fn next_u64(&mut self) -> u64 {
/// // Your implementation here
/// self.state
/// }
/// }
/// ```