pub struct Linear16 { /* private fields */ }
Expand description
16-bit Galois linear feedback shift register. This generator has an extremely short period of 65535.
§Example
use rand_core::{SeedableRng, RngCore};
use lineargen::Linear16;
let mut rng = Linear16::seed_from_u64(1234567);
for _ in 0..100 { rng.next_u32(); }
assert_eq!(1407506474, rng.next_u32());
Implementations§
Source§impl Linear16
impl Linear16
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) -> u16
pub fn dump_state(&self) -> u16
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 Linear16
impl RngCore for Linear16
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 Linear16
impl SeedableRng for Linear16
Source§type Seed = [u8; 2]
type Seed = [u8; 2]
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