Pseudo RNGs

This works:

const std = @import("std");

pub fn main() !void {
    var prng = std.Random.DefaultPrng.init(@intCast(std.time.nanoTimestamp()));
    const random = prng.random();

    const die = random.intRangeAtMost(u8, 1, 6);
    std.debug.print("{}\n", .{die});
}

The prng.random() call is important here, since it gets you a bunch of nice functions. See here

2 Likes