···18181919let v ~taps ~seed ~width =
2020 if width < 1 || width > 62 then
2121- invalid_arg (Printf.sprintf "Lfsr.v: width %d not in [1, 62]" width);
2121+ invalid_arg (Fmt.str "Lfsr.v: width %d not in [1, 62]" width);
2222 let mask = if width = 62 then max_int else (1 lsl width) - 1 in
2323 { taps; width; mask; state = seed land mask }
2424
+5-5
test/test_lfsr.ml
···88 Bytes.iteri
99 (fun i c ->
1010 if i > 0 then Buffer.add_char buf ' ';
1111- Buffer.add_string buf (Printf.sprintf "%02X" (Char.code c)))
1111+ Buffer.add_string buf (Fmt.str "%02X" (Char.code c)))
1212 b;
1313 Buffer.contents buf
1414···9393 for _ = 1 to 1000 do
9494 let bit = Lfsr.step t in
9595 if bit <> 0 && bit <> 1 then
9696- Alcotest.fail (Printf.sprintf "step returned %d, expected 0 or 1" bit)
9696+ Alcotest.fail (Fmt.str "step returned %d, expected 0 or 1" bit)
9797 done
98989999(* next_byte returns 0-255 *)
···102102 for _ = 1 to 1000 do
103103 let b = Lfsr.next_byte t in
104104 if b < 0 || b > 255 then
105105- Alcotest.fail (Printf.sprintf "next_byte returned %d" b)
105105+ Alcotest.fail (Fmt.str "next_byte returned %d" b)
106106 done
107107108108(* 32-bit LFSR with maximal polynomial has period 2^32-1. Verify state
···112112 for i = 1 to 100_000 do
113113 ignore (Lfsr.step t);
114114 if Lfsr.state t = 0 then
115115- Alcotest.fail (Printf.sprintf "state became zero at step %d" i)
115115+ Alcotest.fail (Fmt.str "state became zero at step %d" i)
116116 done
117117118118(* {1 CCSDS TM frame randomizer test vectors}
···161161 let s = Lfsr.state t in
162162 if Hashtbl.mem seen s then begin
163163 all_unique := false;
164164- Printf.printf "duplicate state %d at step %d\n" s i
164164+ Fmt.pr "duplicate state %d at step %d\n" s i
165165 end;
166166 Hashtbl.replace seen s true
167167 done;