pub trait LinearRng:
Sized
+ Send
+ Sync {
// Required methods
fn new(seed: u32) -> Self;
fn compute(&self, index: u32) -> f32;
// Provided methods
fn dither<T>(
&self,
value: T,
min: T,
one: T,
dither_amplitude: T,
index: u32,
) -> T
where T: DitherFloat,
Self: Sized { ... }
fn simple_dither<T>(&self, value: T, one: T, index: u32) -> T
where T: DitherFloat + Number + CastableFrom<f32>,
Self: Sized { ... }
fn dither_slice<T>(
&self,
values: &mut [T],
min: T,
one: T,
dither_amplitude: T,
)
where T: DitherFloat + Send + Sync,
Self: Sized { ... }
fn simple_dither_slice<T>(&self, values: &mut [T], one: T)
where T: DitherFloat + Number + CastableFrom<f32> + Send + Sync,
Self: Sized { ... }
fn dither_iter<T, I>(
&self,
values: I,
min: T,
one: T,
dither_amplitude: T,
) -> Vec<T>
where T: DitherFloat + Send + Sync,
I: IntoIterator<Item = T>,
I::IntoIter: Send,
Self: Sized { ... }
fn simple_dither_iter<T, I>(&self, values: I, one: T) -> Vec<T>
where T: DitherFloat + Number + CastableFrom<f32> + Send + Sync,
I: IntoIterator<Item = T>,
I::IntoIter: Send,
Self: Sized { ... }
fn dither_float<Src, Dest>(&self, value: Src, index: u32) -> Dest
where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64>,
Self: Sized { ... }
fn dither_float_slice<Src, Dest>(&self, values: &[Src]) -> Vec<Dest>
where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Copy + Send + Sync,
Dest: Send,
Self: Sized { ... }
fn dither_float_iter<Src, Dest, I>(&self, values: I) -> Vec<Dest>
where Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Send + Sync,
Dest: Send,
I: IntoIterator<Item = Src>,
I::IntoIter: Send,
Self: Sized { ... }
}Expand description
Trait for linear (1D) random number generators.
These generators produce deterministic random values based on a single index, making them ideal for sequential processing and 1D dithering applications.
§When to Use LinearRng
Use LinearRng implementations when:
- Processing data sequentially (arrays, streams).
- Dithering images as flat pixel arrays.
- You need consistent results with a given seed.
- Memory efficiency matters (no lookup tables).
§Available Implementations
Hash– Fast hash-based RNG. Good general-purpose quality with uniform distribution.R2– Low-discrepancy sequence using the R2 recurrence. Better spatial distribution than random.GoldenRatio– Golden ratio sequence. Optimal 1D coverage with minimal clustering.
Required Methods§
Provided Methods§
Sourcefn dither<T>(
&self,
value: T,
min: T,
one: T,
dither_amplitude: T,
index: u32,
) -> Twhere
T: DitherFloat,
Self: Sized,
fn dither<T>(
&self,
value: T,
min: T,
one: T,
dither_amplitude: T,
index: u32,
) -> Twhere
T: DitherFloat,
Self: Sized,
Dither a single value.
Sourcefn simple_dither<T>(&self, value: T, one: T, index: u32) -> T
fn simple_dither<T>(&self, value: T, one: T, index: u32) -> T
Simple dither for a single value.
Sourcefn dither_slice<T>(&self, values: &mut [T], min: T, one: T, dither_amplitude: T)
fn dither_slice<T>(&self, values: &mut [T], min: T, one: T, dither_amplitude: T)
Dither values in a slice (parallel version).
Sourcefn simple_dither_slice<T>(&self, values: &mut [T], one: T)
fn simple_dither_slice<T>(&self, values: &mut [T], one: T)
Simple dither for values in a slice (parallel version).
Sourcefn dither_iter<T, I>(
&self,
values: I,
min: T,
one: T,
dither_amplitude: T,
) -> Vec<T>
fn dither_iter<T, I>( &self, values: I, min: T, one: T, dither_amplitude: T, ) -> Vec<T>
Dither values from an iterator (parallel version).
Sourcefn simple_dither_iter<T, I>(&self, values: I, one: T) -> Vec<T>where
T: DitherFloat + Number + CastableFrom<f32> + Send + Sync,
I: IntoIterator<Item = T>,
I::IntoIter: Send,
Self: Sized,
fn simple_dither_iter<T, I>(&self, values: I, one: T) -> Vec<T>where
T: DitherFloat + Number + CastableFrom<f32> + Send + Sync,
I: IntoIterator<Item = T>,
I::IntoIter: Send,
Self: Sized,
Simple dither for values from an iterator (parallel version).
Sourcefn dither_float<Src, Dest>(&self, value: Src, index: u32) -> Dest
fn dither_float<Src, Dest>(&self, value: Src, index: u32) -> Dest
Dither a float value when converting to lower precision.
Sourcefn dither_float_slice<Src, Dest>(&self, values: &[Src]) -> Vec<Dest>where
Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Copy + Send + Sync,
Dest: Send,
Self: Sized,
fn dither_float_slice<Src, Dest>(&self, values: &[Src]) -> Vec<Dest>where
Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Copy + Send + Sync,
Dest: Send,
Self: Sized,
Dither float values in a slice when converting to lower precision (parallel version).
Sourcefn dither_float_iter<Src, Dest, I>(&self, values: I) -> Vec<Dest>where
Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Send + Sync,
Dest: Send,
I: IntoIterator<Item = Src>,
I::IntoIter: Send,
Self: Sized,
fn dither_float_iter<Src, Dest, I>(&self, values: I) -> Vec<Dest>where
Src: DitherFloatConversion<Dest> + DitherFloat + CastableFrom<f64> + Send + Sync,
Dest: Send,
I: IntoIterator<Item = Src>,
I::IntoIter: Send,
Self: Sized,
Dither float values from an iterator when converting to lower precision (parallel version).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.