Files
WrldBox/.tmp_zig/lib/zig/std/Random/lcg.zig
swim67667 c17dfc94ce
Some checks failed
Build Project / build (ubuntu-latest) (push) Failing after 12m33s
added multi-compiling stuff (only works on my mac for now)
2026-06-28 16:40:20 -04:00

29 lines
600 B
Zig

//! Linear congruential generator
//!
//! X(n+1) = (a * Xn + c) mod m
//!
//! PRNG
const std = @import("std");
/// Linear congruent generator where the modulo is `std.math.maxInt(T)`,
/// wrapping over the integer.
pub fn Wrapping(comptime T: type) type {
return struct {
xi: T,
a: T,
c: T,
pub fn init(xi: T, a: T, c: T) LcgSelf {
return .{ .xi = xi, .a = a, .c = c };
}
pub fn next(lcg: *LcgSelf) T {
lcg.xi = (lcg.a *% lcg.xi) +% lcg.c;
return lcg.xi;
}
const LcgSelf = @This();
};
}