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 › c/ › stdlib/ › rand.zig
rand.zig
Index
File
Code
const builtin = @import ("builtin" );
const std = @import ("std" );
const symbol = @import ("../../c.zig" ).symbol ;
comptime {
if (builtin .target .isMuslLibC () or builtin .target .isWasiLibC ()) {
symbol (&rand , "rand" );
symbol (&srand , "srand" );
symbol (&rand_r , "rand_r" );
}
}
var rand_state : std .Random .SplitMix64 = .init (1 );
fn rand_r (seed : *c_uint ) callconv (.c ) c_int {
var mix : std .Random .SplitMix64 = .init (seed .*);
defer seed .* = @truncate (mix .s );
return @as (u31 , @truncate (mix .next () >> 33 ));
}
fn srand (seed : c_uint ) callconv (.c ) void {
rand_state = .init (seed );
}
fn rand () callconv (.c ) c_int {
return @as (u31 , @truncate (rand_state .next () >> 33 ));
}