pub struct PCG32K<const K: usize> {
pub state: u64,
pub ext: [u32; K],
}
Expand description
A Permuted Congruential Generator with 32-bit output, extended to K
dimensions.
This is like the PCG32, but replaces the single inc
field with an
extension array of K
elements. At each step of the generator a different
element of the array is XOR
-ed with the output, and every time the
generator passes 0 the array is advanced. Given enough time, the entire
extension array will increment through all values (as if it were a
32*K
-bit number). This gives a radically larger generator period than the
basic PCG32
, and guarantees that any sequence of K
outputs in a row will
appear at least once within the generator’s full output stream. Of course
it’s highly unlikely that your program will ever advance the generator
through all possible states, but just the possibility that a given output
sequence will definitely eventually occur can be comfort enough.
For best results, K
should be a power of 2. The type works with other K
values, but when K
is a power of 2 then selecting an element from the
extension array is significantly faster (a bit mask instead of an integer
division).
- Period:
2**(64+32*k)
Fields§
§state: u64
The generator’s state.
This changes with each step of the generator. It’s the generator’s “position” within the output stream.
ext: [u32; K]
The generator’s extension array. The generator’s base output is XOR’d with random elements of this array to determine the final output at each step.
Implementations§
source§impl<const K: usize> PCG32K<K>
impl<const K: usize> PCG32K<K>
sourcepub const fn new(state: u64, ext: [u32; K]) -> Self
pub const fn new(state: u64, ext: [u32; K]) -> Self
Creates a new generator by directly using the value given.
sourcepub fn from_getrandom() -> Result<Self, Error>
Available on crate feature getrandom
only.
pub fn from_getrandom() -> Result<Self, Error>
getrandom
only.sourcepub fn scramble_ext_array(&mut self) -> Result<(), Error>
Available on crate feature getrandom
only.
pub fn scramble_ext_array(&mut self) -> Result<(), Error>
getrandom
only.