Struct Linear32

Source
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

Source

pub fn clock(&mut self)

Clock the LFSR once without generating a number.

Source

pub fn clock_rev(&mut self)

Clock the LFSR in reverse.

Source

pub fn quick_bool(&mut self) -> bool

Returns true if the least significant bit is one, else returns false. The LFSR is clocked once.

Source

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.

Source

pub fn dump_state(&self) -> u32

Returns the current state of the LFSR.

Source

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.

Source

pub fn inverse_state(&mut self)

Negates the bits of the state.

Source

pub fn get_32bits(&mut self) -> u32

Generates a 32-bit unsigned integer. You might want to use next_u32() from RngCore instead.

Source

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.

Source

pub fn get_64bits(&mut self) -> u64

Generates a 64-bit unsigned integer. You might want to use next_u64() from RngCore instead.

Source

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

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more
Source§

impl SeedableRng for Linear32

Source§

type Seed = [u8; 4]

Seed type, which is restricted to types mutably-dereferenceable as u8 arrays (we recommend [u8; N] for some N). Read more
Source§

fn from_seed(seed: [u8; 4]) -> Self

Create a new PRNG using the given seed. Read more
Source§

fn seed_from_u64(seed: u64) -> Self

Create a new PRNG using a u64 seed. Read more
Source§

fn from_rng<R>(rng: R) -> Result<Self, Error>
where R: RngCore,

Create a new PRNG seeded from another Rng. Read more
Source§

fn from_entropy() -> Self

Creates a new instance of the RNG seeded via getrandom. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.