Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › Io/ › Dispatch.zig › Random
Random
Dispatch.Random
const Random = struct
File
Code
const Random = struct {
evented : *Evented ,
thread : *Thread ,
buffer : []u8 ,
fn seed (context : ?*anyopaque ) callconv (.c ) void {
const rand : *Random = @ptrCast (@alignCast (context ));
const ev = rand .evented ;
ev .csprng_mutex .lockUncancelable (ev );
defer ev .csprng_mutex .unlock ();
var buffer : [Csprng .seed_len ]u8 = undefined ;
if (!ev .csprng .isInitialized ()) {
@branchHint (.unlikely );
const cancel_protection = swapCancelProtection (ev , .blocked );
defer assert (swapCancelProtection (ev , cancel_protection ) == .blocked );
randomSecure (ev , &buffer ) catch |err | switch (err ) {
error .Canceled => unreachable ,
error .EntropyUnavailable => fallbackSeed (ev , &buffer ),
};
ev .csprng .rng = .init (buffer );
}
ev .csprng .rng .fill (&buffer );
rand .thread .csprng .rng = .init (buffer );
rand .thread .csprng .rng .fill (rand .buffer );
rand .buffer .len = 0 ;
}
}