authorgravatar for matthew.h.borkowski@gmail.comMatthew Borkowski <matthew.h.borkowski@gmail.com> 2021-03-28 09:49:10-04:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-29 09:22:06+02:00
loga5cc5f7854b87f3daaff790deb6dec72b329f432
tree475397b776402bbe3f2e405be0add7b10b393bfc
parent175adc0bd738c2e3a55bb71c6a53dcc920c203ba

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.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/rand/Pcg.zig+1-1
......@@ -75,7 +75,7 @@ fn fill(r: *Random, buf: []u8) void {
7575 var n = self.next();
7676 while (i < buf.len) : (i += 1) {
7777 buf[i] = @truncate(u8, n);
78 n >>= 4;
78 n >>= 8;
7979 }
8080 }
8181}