Linear congruential generator
X(n+1) = (a * Xn + c) mod m
PRNG
std.Random.lcg.std
alias
Alias of std
std.Random.lcg.Wrapping
type-function
Linear congruent generator where the modulo is std.math.maxInt(T),
wrapping over the integer.
pub fn Wrapping(comptime T: type) type
Parameters
T: type
Fields
xi: T
a: T
c: T
std.Random.lcg.Wrapping.init
function
pub fn init(xi: T, a: T, c: T) LcgSelf
Parameters
xi: T
a: T
c: T
std.Random.lcg.Wrapping.LcgSelf
alias
Alias of std.Random.lcg.Wrapping
std.Random.lcg.Wrapping.next
function
pub fn next(lcg: *LcgSelf) T
Parameters
lcg: *LcgSelf
Source code
std/Random/lcg.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();
};
}