From e073c8a2b1570b24a659ebaeddacf957c15229fa Mon Sep 17 00:00:00 2001 From: Charles Shenton Date: Fri, 17 Apr 2020 14:29:02 +0100 Subject: [PATCH 1/3] Update ziggurat.zig to use `random.int(u64)` Ziggurat rng was using deprecated `random.scalar(u64)` which was causing compile errors on calls to public facing stdlib APIs (randExp) on 0.6+, this fixed those errors. --- lib/std/rand/ziggurat.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/rand/ziggurat.zig b/lib/std/rand/ziggurat.zig index c29d3eeb2..a9b11bf4a 100644 --- a/lib/std/rand/ziggurat.zig +++ b/lib/std/rand/ziggurat.zig @@ -16,7 +16,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { while (true) { // We manually construct a float from parts as we can avoid an extra random lookup here by // using the unused exponent for the lookup table entry. - const bits = random.scalar(u64); + const bits = random.int(u64); const i = @as(usize, bits & 0xff); const u = blk: { From ca38b188798cda8377c56cdbd0858df08f8c503f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 18 Apr 2020 14:41:25 -0400 Subject: [PATCH 2/3] rand: ref the decls so they get tested --- lib/std/rand.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/std/rand.zig b/lib/std/rand.zig index 5b4655bc5..299d87d39 100644 --- a/lib/std/rand.zig +++ b/lib/std/rand.zig @@ -1123,3 +1123,7 @@ fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void { } } } + +test "" { + std.meta.refAllDecls(@This()); +} From 3817420d42dd07fa9a48e1a7521cb520539b6f64 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 18 Apr 2020 14:41:33 -0400 Subject: [PATCH 3/3] ziggurat uses `@truncate` instead of `& 0xff` This makes it work on 32-bit targets. closes #2939 --- lib/std/rand/ziggurat.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/rand/ziggurat.zig b/lib/std/rand/ziggurat.zig index a9b11bf4a..06728f170 100644 --- a/lib/std/rand/ziggurat.zig +++ b/lib/std/rand/ziggurat.zig @@ -17,7 +17,7 @@ pub fn next_f64(random: *Random, comptime tables: ZigTable) f64 { // We manually construct a float from parts as we can avoid an extra random lookup here by // using the unused exponent for the lookup table entry. const bits = random.int(u64); - const i = @as(usize, bits & 0xff); + const i = @as(usize, @truncate(u8, bits)); const u = blk: { if (tables.is_symmetric) {