From 9dc02154401fb612ad8898faf63ff621848a26e5 Mon Sep 17 00:00:00 2001 From: George Abbott Date: Tue, 28 Nov 2023 23:40:30 +0000 Subject: gitignore update --- src/main.zig | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index afe9380..1252e9d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,13 +6,14 @@ const RngGen = std.rand.DefaultPrng; // ~LMH~M~L // Where ~ specifies the next char is optional. -pub fn randomIndex(rnd: std.rand.Random, arr: [][]const u8) usize { - const index = @mod(rnd.int(usize), arr.*.len); +pub fn randomIndex(rnd: std.rand.Random, arr: anytype) usize { + const index = @mod(rnd.int(usize), arr.len); return index; } pub fn main() !void { - var rnd = RngGen.init(0); + const seed: u64 = @bitCast(std.time.timestamp()); + var rnd = RngGen.init(seed); var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) @@ -40,20 +41,20 @@ pub fn main() !void { switch (char) { 'L' => { - output.append(low_sonor[randomIndex(rnd.random(), &low_sonor)]); + try output.appendSlice(low_sonor[randomIndex(rnd.random(), low_sonor)]); }, 'M' => { - output.append(mid_sonor[randomIndex(rnd.random(), &mid_sonor)]); + try output.appendSlice(mid_sonor[randomIndex(rnd.random(), mid_sonor)]); }, 'H' => { - output.append(high_sonor[randomIndex(rnd.random(), &high_sonor)]); + try output.appendSlice(high_sonor[randomIndex(rnd.random(), high_sonor)]); }, else => { - std.debug.print("Invalid char {s}", .{char}); + std.debug.print("Invalid char {}", .{char}); }, } } - std.debug.print("Result: {}", .{output}); + std.debug.print("Result: {s}\n", .{try output.toOwnedSlice()}); } -- cgit v1.2.1