summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Abbott <george@gabbott.dev>2023-11-28 23:40:30 +0000
committerGeorge Abbott <george@gabbott.dev>2023-11-28 23:40:30 +0000
commit9dc02154401fb612ad8898faf63ff621848a26e5 (patch)
treeb1c7d201178af2e58acf3454ab98695dc4810a7b
parent4626fb970da118dd41586668224fc331cebc24c2 (diff)
gitignore updateHEADmaster
-rw-r--r--.gitignore1
-rw-r--r--src/main.zig17
2 files changed, 10 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 3cef7be..e73c965 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
zig-cache/
+zig-out/
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()});
}