~jshholland/doomsday

b5376a6950ec3a5c8f99d3b850049574b2a23ed5 — Josh Holland a month ago d09fc44 zig-0.8
update for Zig 0.8

Change @TagType to std.meta.Tag and fix crypto API use.
1 files changed, 4 insertions(+), 6 deletions(-)

M src/main.zig
M src/main.zig => src/main.zig +4 -6
@@ 38,7 38,7 @@ const Month = enum {

fn randDate(r: *Random) Date {
    const y = r.intRangeLessThan(u16, 1600, 2500);
    const m = @intToEnum(Month, r.intRangeAtMost(@TagType(Month), 1, 12));
    const m = @intToEnum(Month, r.intRangeAtMost(std.meta.Tag(Month), 1, 12));
    const d = r.intRangeAtMost(u8, 1, m.numDays(isLeap(y)));
    return Date{ .year = y, .month = m, .day = d };
}


@@ 75,7 75,7 @@ const Date = struct {
            .December => 12,
        };
        // add 35 (0 mod 7) to avoid underflow, since d is at most 29
        return @intToEnum(Day, @intCast(@TagType(Day), (self.day + 35 - d + dd) % 7));
        return @intToEnum(Day, @intCast(std.meta.Tag(Day), (self.day + 35 - d + dd) % 7));
    }
};



@@ 121,7 121,7 @@ test "doomsday calculation" {
}

fn readDay(b: []const u8) ?Day {
    const i = parseInt(@TagType(Day), std.mem.trim(u8, b, " \n"), 10) catch return null;
    const i = parseInt(std.meta.Tag(Day), std.mem.trim(u8, b, " \n"), 10) catch return null;
    if (i >= 7) return null;
    return @intToEnum(Day, i);
}


@@ 174,9 174,7 @@ pub fn main() !void {
        break :blk res;
    };

    var seed: u64 = undefined;
    try std.crypto.randomBytes(std.mem.asBytes(&seed));
    const rand = &std.rand.DefaultPrng.init(seed).random;
    const rand = &std.rand.DefaultPrng.init(std.crypto.random.int(u64)).random;

    var asked: usize = 0;
    while (asked < num_questions) : (asked += 1) {