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/ › Random/ › ziggurat.zig › ZigTableGen
ZigTableGen
ziggurat.ZigTableGen
pub fn ZigTableGen (
comptime is_symmetric : bool ,
comptime r : f64 ,
comptime v : f64 ,
comptime f : fn (f64 ) f64 ,
comptime f_inv : fn (f64 ) f64 ,
comptime zero_case : fn (Random , f64 ) f64 ,
) ZigTable
File
Code
pub fn ZigTableGen (
comptime is_symmetric : bool ,
comptime r : f64 ,
comptime v : f64 ,
comptime f : fn (f64 ) f64 ,
comptime f_inv : fn (f64 ) f64 ,
comptime zero_case : fn (Random , f64 ) f64 ,
) ZigTable {
var tables : ZigTable = undefined ;
tables .is_symmetric = is_symmetric ;
tables .r = r ;
tables .pdf = f ;
tables .zero_case = zero_case ;
tables .x [0 ] = v / f (r );
tables .x [1 ] = r ;
for (tables .x [2 ..256 ], 0 ..) |*entry , i | {
const last = tables .x [2 + i - 1 ];
entry .* = f_inv (v / last + f (last ));
}
tables .x [256 ] = 0 ;
for (tables .f [0 ..], 0 ..) |*entry , i | {
entry .* = f (tables .x [i ]);
}
return tables ;
}