pub struct Linear32 { /* private fields */ }
Expand description
32-bit Galois linear feedback shift register. Period length is 232-1.
§Example
use rand_core::{SeedableRng, RngCore};
use lineargen::Linear32;
let mut rng = Linear32::seed_from_u64(987654);
for _ in 0..50 { rng.next_u64(); }
assert_eq!(0x9F040BC97563A834, rng.next_u64());
Implementations§
Source§impl Linear32
impl Linear32
Sourcepub fn quick_bool(&mut self) -> bool
pub fn quick_bool(&mut self) -> bool
Returns true
if the least significant bit
is one, else returns false
. The LFSR is
clocked once.
Sourcepub fn quick_bool_rev(&mut self) -> bool
pub fn quick_bool_rev(&mut self) -> bool
Returns true
if the most significant bit is
one, else returns false
. The LFSR is
clocked backwards.
Sourcepub fn dump_state(&self) -> u32
pub fn dump_state(&self) -> u32
Returns the current state of the LFSR.
Sourcepub fn reverse_state(&mut self)
pub fn reverse_state(&mut self)
Reverses the bits of the state, i.e. the least significant bit becomes the most significant one and vice versa.
Sourcepub fn inverse_state(&mut self)
pub fn inverse_state(&mut self)
Negates the bits of the state.
Sourcepub fn get_32bits(&mut self) -> u32
pub fn get_32bits(&mut self) -> u32
Generates a 32-bit unsigned integer.
You might want to use next_u32()
from RngCore
instead.
Sourcepub fn get_32bits_rev(&mut self) -> u32
pub fn get_32bits_rev(&mut self) -> u32
Generates a 32-bit unsigned integer by clocking the LFSR in reverse (left shift).
Note, that this will not just return the numbers
generated with get_32bits()
in reverse order.
Sourcepub fn get_64bits(&mut self) -> u64
pub fn get_64bits(&mut self) -> u64
Generates a 64-bit unsigned integer.
You might want to use next_u64()
from RngCore
instead.
Sourcepub fn get_64bits_rev(&mut self) -> u64
pub fn get_64bits_rev(&mut self) -> u64
Generates a 64-bit unsigned integer by clocking the LFSR in reverse (left shift).
Note, that this will not just return the numbers
generated with get_64bits()
in reverse order.
Trait Implementations§
Source§impl RngCore for Linear32
impl RngCore for Linear32
Source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moreSource§impl SeedableRng for Linear32
impl SeedableRng for Linear32
Source§type Seed = [u8; 4]
type Seed = [u8; 4]
u8
arrays (we recommend [u8; N]
for some N
). Read moreSource§fn seed_from_u64(seed: u64) -> Self
fn seed_from_u64(seed: u64) -> Self
u64
seed. Read moreSource§fn from_rng<R>(rng: R) -> Result<Self, Error>where
R: RngCore,
fn from_rng<R>(rng: R) -> Result<Self, Error>where
R: RngCore,
Rng
. Read more