aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/rand.zig7
-rw-r--r--lib/std/rand/Gimli.zig2
-rw-r--r--lib/std/rand/Isaac64.zig2
-rw-r--r--lib/std/rand/Pcg.zig2
-rw-r--r--lib/std/rand/Sfc64.zig2
-rw-r--r--lib/std/rand/Xoroshiro128.zig2
-rw-r--r--lib/std/rand/Xoshiro256.zig2
7 files changed, 9 insertions, 10 deletions
diff --git a/lib/std/rand.zig b/lib/std/rand.zig
index 7a638a76b3..ce3204b4d0 100644
--- a/lib/std/rand.zig
+++ b/lib/std/rand.zig
@@ -32,17 +32,16 @@ pub const Random = struct {
ptr: *c_void,
fillFn: fn (ptr: *c_void, buf: []u8) void,
- pub fn init(pointer: anytype) Random {
+ pub fn init(pointer: anytype, comptime fillFn: fn (ptr: @TypeOf(pointer), buf: []u8) void) Random {
const Ptr = @TypeOf(pointer);
assert(@typeInfo(Ptr) == .Pointer); // Must be a pointer
assert(@typeInfo(Ptr).Pointer.size == .One); // Must be a single-item pointer
assert(@typeInfo(@typeInfo(Ptr).Pointer.child) == .Struct); // Must point to a struct
- assert(std.meta.trait.hasFn("fill")(@typeInfo(Ptr).Pointer.child)); // Struct must provide the `fill` function
const gen = struct {
fn fill(ptr: *c_void, buf: []u8) void {
const alignment = @typeInfo(Ptr).Pointer.alignment;
const self = @ptrCast(Ptr, @alignCast(alignment, ptr));
- self.fill(buf);
+ fillFn(self, buf);
}
};
@@ -333,7 +332,7 @@ const SequentialPrng = struct {
}
pub fn random(self: *Self) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
pub fn fill(self: *Self, buf: []u8) void {
diff --git a/lib/std/rand/Gimli.zig b/lib/std/rand/Gimli.zig
index 0a95b2fd43..7b7720503e 100644
--- a/lib/std/rand/Gimli.zig
+++ b/lib/std/rand/Gimli.zig
@@ -21,7 +21,7 @@ pub fn init(secret_seed: [secret_seed_length]u8) Gimli {
}
pub fn random(self: *Gimli) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
pub fn fill(self: *Gimli, buf: []u8) void {
diff --git a/lib/std/rand/Isaac64.zig b/lib/std/rand/Isaac64.zig
index 787d8fc29d..42242008fc 100644
--- a/lib/std/rand/Isaac64.zig
+++ b/lib/std/rand/Isaac64.zig
@@ -31,7 +31,7 @@ pub fn init(init_s: u64) Isaac64 {
}
pub fn random(self: *Isaac64) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2: usize) void {
diff --git a/lib/std/rand/Pcg.zig b/lib/std/rand/Pcg.zig
index 0129e75533..3d62c5cfa9 100644
--- a/lib/std/rand/Pcg.zig
+++ b/lib/std/rand/Pcg.zig
@@ -22,7 +22,7 @@ pub fn init(init_s: u64) Pcg {
}
pub fn random(self: *Pcg) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
fn next(self: *Pcg) u32 {
diff --git a/lib/std/rand/Sfc64.zig b/lib/std/rand/Sfc64.zig
index 9be44b06a9..a5e6920df7 100644
--- a/lib/std/rand/Sfc64.zig
+++ b/lib/std/rand/Sfc64.zig
@@ -24,7 +24,7 @@ pub fn init(init_s: u64) Sfc64 {
}
pub fn random(self: *Sfc64) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
fn next(self: *Sfc64) u64 {
diff --git a/lib/std/rand/Xoroshiro128.zig b/lib/std/rand/Xoroshiro128.zig
index ba103bcf20..60907a017b 100644
--- a/lib/std/rand/Xoroshiro128.zig
+++ b/lib/std/rand/Xoroshiro128.zig
@@ -17,7 +17,7 @@ pub fn init(init_s: u64) Xoroshiro128 {
}
pub fn random(self: *Xoroshiro128) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
fn next(self: *Xoroshiro128) u64 {
diff --git a/lib/std/rand/Xoshiro256.zig b/lib/std/rand/Xoshiro256.zig
index 53cac3d5be..b81b5178aa 100644
--- a/lib/std/rand/Xoshiro256.zig
+++ b/lib/std/rand/Xoshiro256.zig
@@ -19,7 +19,7 @@ pub fn init(init_s: u64) Xoshiro256 {
}
pub fn random(self: *Xoshiro256) Random {
- return Random.init(self);
+ return Random.init(self, fill);
}
fn next(self: *Xoshiro256) u64 {