summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig17
1 files changed, 9 insertions, 8 deletions
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()});
}