Operations that need randomness receive the same std.Io context. std.Io.randomSecure uses the context’s secure random source and fills a caller-owned buffer. The existing Network recipes demonstrate the related std.Io.net interfaces for TCP, UDP, DNS, and HTTP operations.

//! Get random bytes through the Io context.

const std = @import("std");

pub fn main(init: std.process.Init) !void {
    var random_bytes: [8]u8 = undefined;
    try std.Io.randomSecure(init.io, &random_bytes);

    std.debug.print("secure random bytes: {x}\n", .{random_bytes});
}