From a5cc5f7854b87f3daaff790deb6dec72b329f432 Mon Sep 17 00:00:00 2001 From: Matthew Borkowski Date: Sun, 28 Mar 2021 09:49:10 -0400 Subject: [PATCH] Fix typo in Pcg.zig's fill function When filling the last (len % 4) bytes of a buffer, the random number n was only being shifted right by 4 bits for each byte instead of 8. A random u16, for example, would always have its middle two nybbles be equal when generated this way. For comparison, Isaac64.zig, Sfc64.zig, and Xoroshiro128.zig all correctly shift right by 8 bits for each of the last bytes in their nearly identical fill functions. --- lib/std/rand/Pcg.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/rand/Pcg.zig b/lib/std/rand/Pcg.zig index 6be17b3bb8..0d62eb8d25 100644 --- a/lib/std/rand/Pcg.zig +++ b/lib/std/rand/Pcg.zig @@ -75,7 +75,7 @@ fn fill(r: *Random, buf: []u8) void { var n = self.next(); while (i < buf.len) : (i += 1) { buf[i] = @truncate(u8, n); - n >>= 4; + n >>= 8; } } }