Std.os.getrandom missing?

I’m basically following the example here for a RNG:

const std = @import("std");
const expect = std.testing.expect;

// Random number generator used all over
pub fn ourRng() !std.rand.DefaultPrng {
    return std.rand.DefaultPrng.init(blk: {
        var seed: u64 = undefined;
        try std.os.getrandom(std.mem.asBytes(&seed));
        break :blk seed;
    });
}

But I get the error that

error: root struct of file 'os' has no member named 'getrandom'

That’s exactly the case, but I’m a bit lost on how to use the new? stdRandom for the same purpose. Once I get that done, I will dutifully make a PR to the documentation

std.os renamed to std.posix in zig 0.12.0.

You are looking for std.posix.getrandom.

1 Like

I went as promised to fix the guide and I see it’s already fixed The issue seems to be that the latest version is not deployed as such in the site?

Zig Gude is not an official resource by the zig team. You’d have to query on GitHub to see why it’s hasn’t been updated on the live site.

1 Like