pub struct HashedPermutation {
pub seed: u32,
pub length: NonZeroU32,
}
Expand description
The HashedPermutation
struct stores the initial seed
and length
of the permutation
vector. In other words, if you want to shuffle the numbers from 0..n
, then length = n
.
Because the shuffle is performed using bit arithmetic, the fields have to be 32 bit integers. Unfortunately, larger types are not supported at this time.
Fields§
§seed: u32
The random seed that dictates which permutation you want to use. The shuffle is deterministic, so using the same seed will yield the same permutation every time.
length: NonZeroU32
The upper bound on the range of numbers to shuffle (from 0..length
). This value must be
greater zero, otherwise undefined behavior may occur.
Implementations§
Source§impl HashedPermutation
impl HashedPermutation
Sourcepub fn new_with_seed(length: NonZeroU32, seed: u32) -> Self
pub fn new_with_seed(length: NonZeroU32, seed: u32) -> Self
Create a new instance of the hashed permutation given a length and seed
Sourcepub fn shuffle(&self, input: u32) -> PermutationResult<u32>
pub fn shuffle(&self, input: u32) -> PermutationResult<u32>
Shuffle or permute a particular value.
This method uses the technique described in Kensler’s paper to perform an in-place shuffle with no memory overhead.
Trait Implementations§
Source§impl Clone for HashedPermutation
impl Clone for HashedPermutation
Source§fn clone(&self) -> HashedPermutation
fn clone(&self) -> HashedPermutation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more