mirror of
https://github.com/ziglang/zig.git
synced 2024-12-03 18:38:45 +00:00
publicize std.rand.ziggurat
This commit is contained in:
parent
21c258acac
commit
129afba460
@ -11,7 +11,6 @@ const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
const ziggurat = @import("rand/ziggurat.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
/// Fast unbiased random numbers.
|
||||
@ -29,6 +28,7 @@ pub const Xoroshiro128 = @import("rand/Xoroshiro128.zig");
|
||||
pub const Xoshiro256 = @import("rand/Xoshiro256.zig");
|
||||
pub const Sfc64 = @import("rand/Sfc64.zig");
|
||||
pub const RomuTrio = @import("rand/RomuTrio.zig");
|
||||
pub const ziggurat = @import("rand/ziggurat.zig");
|
||||
|
||||
pub const Random = struct {
|
||||
ptr: *anyopaque,
|
||||
|
@ -65,7 +65,7 @@ pub const ZigTable = struct {
|
||||
};
|
||||
|
||||
// zigNorInit
|
||||
fn ZigTableGen(
|
||||
pub fn ZigTableGen(
|
||||
comptime is_symmetric: bool,
|
||||
comptime r: f64,
|
||||
comptime v: f64,
|
||||
@ -102,16 +102,16 @@ pub const NormDist = blk: {
|
||||
break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case);
|
||||
};
|
||||
|
||||
const norm_r = 3.6541528853610088;
|
||||
const norm_v = 0.00492867323399;
|
||||
pub const norm_r = 3.6541528853610088;
|
||||
pub const norm_v = 0.00492867323399;
|
||||
|
||||
fn norm_f(x: f64) f64 {
|
||||
pub fn norm_f(x: f64) f64 {
|
||||
return @exp(-x * x / 2.0);
|
||||
}
|
||||
fn norm_f_inv(y: f64) f64 {
|
||||
pub fn norm_f_inv(y: f64) f64 {
|
||||
return @sqrt(-2.0 * @log(y));
|
||||
}
|
||||
fn norm_zero_case(random: Random, u: f64) f64 {
|
||||
pub fn norm_zero_case(random: Random, u: f64) f64 {
|
||||
var x: f64 = 1;
|
||||
var y: f64 = 0;
|
||||
|
||||
@ -143,16 +143,16 @@ pub const ExpDist = blk: {
|
||||
break :blk ZigTableGen(false, exp_r, exp_v, exp_f, exp_f_inv, exp_zero_case);
|
||||
};
|
||||
|
||||
const exp_r = 7.69711747013104972;
|
||||
const exp_v = 0.0039496598225815571993;
|
||||
pub const exp_r = 7.69711747013104972;
|
||||
pub const exp_v = 0.0039496598225815571993;
|
||||
|
||||
fn exp_f(x: f64) f64 {
|
||||
pub fn exp_f(x: f64) f64 {
|
||||
return @exp(-x);
|
||||
}
|
||||
fn exp_f_inv(y: f64) f64 {
|
||||
pub fn exp_f_inv(y: f64) f64 {
|
||||
return -@log(y);
|
||||
}
|
||||
fn exp_zero_case(random: Random, _: f64) f64 {
|
||||
pub fn exp_zero_case(random: Random, _: f64) f64 {
|
||||
return exp_r - @log(random.float(f64));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user