Linear Feedback Shift Registers for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lfsr: Fmt.pf instead of Format.fprintf (merlint E200)

+5 -5
+2 -2
lib/lfsr.ml
··· 14 14 } 15 15 16 16 let pp ppf t = 17 - Format.fprintf ppf "lfsr(%d, 0x%0*X)" t.width (t.width / 4) t.state 17 + Fmt.pf ppf "lfsr(%d, 0x%0*X)" t.width (t.width / 4) t.state 18 18 19 19 let v ~taps ~seed ~width = 20 20 if width < 1 || width > 62 then 21 - Fmt.invalid_arg "Lfsr.v: width %d not in [1, 62]" width); 21 + Fmt.invalid_arg "Lfsr.v: width %d not in [1, 62]" width; 22 22 let mask = if width = 62 then max_int else (1 lsl width) - 1 in 23 23 { taps; width; mask; state = seed land mask } 24 24
+3 -3
test/test_lfsr.ml
··· 93 93 for _ = 1 to 1000 do 94 94 let bit = Lfsr.step t in 95 95 if bit <> 0 && bit <> 1 then 96 - Alcotest.failf "step returned %d, expected 0 or 1" bit) 96 + Alcotest.failf "step returned %d, expected 0 or 1" bit 97 97 done 98 98 99 99 (* next_byte returns 0-255 *) ··· 102 102 for _ = 1 to 1000 do 103 103 let b = Lfsr.next_byte t in 104 104 if b < 0 || b > 255 then 105 - Alcotest.failf "next_byte returned %d" b) 105 + Alcotest.failf "next_byte returned %d" b 106 106 done 107 107 108 108 (* 32-bit LFSR with maximal polynomial has period 2^32-1. Verify state ··· 112 112 for i = 1 to 100_000 do 113 113 ignore (Lfsr.step t); 114 114 if Lfsr.state t = 0 then 115 - Alcotest.failf "state became zero at step %d" i) 115 + Alcotest.failf "state became zero at step %d" i 116 116 done 117 117 118 118 (* {1 CCSDS TM frame randomizer test vectors}