Skip to main content

lfsr

Function lfsr 

Source
pub fn lfsr(taps: &[usize], order: usize, init: &[u8], len: usize) -> Vec<u8> ⓘ
Expand description

The sequence of a linear-feedback shift register of order order: the first order bits are init (zero-padded), then $x_{i + \mathrm{order}} = \sum_{t} x_{i + t} \bmod 2$ over the taps, up to len bits in all (the Fibonacci form of every m-sequence, Gold sequence and PRBS of the standards).

§Examples

use comnum_math::sequences::lfsr;
// x³ + x + 1: the m-sequence of period 7
let x = lfsr(&[0, 1], 3, &[1, 0, 0], 10);
assert_eq!(x, vec![1, 0, 0, 1, 0, 1, 1, 1, 0, 0]);