Replace std.rand references with std.Random

This commit is contained in:
e4m2 2024-02-08 15:21:35 +01:00
parent 9af077d71e
commit 8d56e472c9
34 changed files with 71 additions and 79 deletions

View file

@ -420,7 +420,7 @@ fn runStepNames(
const starting_steps = try arena.dupe(*Step, step_stack.keys()); const starting_steps = try arena.dupe(*Step, step_stack.keys());
var rng = std.rand.DefaultPrng.init(seed); var rng = std.Random.DefaultPrng.init(seed);
const rand = rng.random(); const rand = rng.random();
rand.shuffle(*Step, starting_steps); rand.shuffle(*Step, starting_steps);
@ -836,7 +836,7 @@ fn constructGraphAndCheckForDependencyLoop(
b: *std.Build, b: *std.Build,
s: *Step, s: *Step,
step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void), step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void),
rand: std.rand.Random, rand: std.Random,
) !void { ) !void {
switch (s.state) { switch (s.state) {
.precheck_started => { .precheck_started => {

View file

@ -26,7 +26,7 @@ test "paritydi2" {
try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffe))); try test__paritydi2(@bitCast(@as(u64, 0xffffffff_fffffffe)));
try test__paritydi2(@bitCast(@as(u64, 0xffffffff_ffffffff))); try test__paritydi2(@bitCast(@as(u64, 0xffffffff_ffffffff)));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -26,7 +26,7 @@ test "paritysi2" {
try test__paritysi2(@bitCast(@as(u32, 0xfffffffe))); try test__paritysi2(@bitCast(@as(u32, 0xfffffffe)));
try test__paritysi2(@bitCast(@as(u32, 0xffffffff))); try test__paritysi2(@bitCast(@as(u32, 0xffffffff)));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -26,7 +26,7 @@ test "parityti2" {
try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))); try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)));
try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))); try test__parityti2(@bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -25,7 +25,7 @@ test "popcountdi2" {
try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe)))); try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_fffffffe))));
try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff)))); try test__popcountdi2(@as(i64, @bitCast(@as(u64, 0xffffffff_ffffffff))));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -25,7 +25,7 @@ test "popcountsi2" {
try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffe)))); try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xfffffffe))));
try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xffffffff)))); try test__popcountsi2(@as(i32, @bitCast(@as(u32, 0xffffffff))));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -25,7 +25,7 @@ test "popcountti2" {
try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe)))); try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_fffffffe))));
try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff)))); try test__popcountti2(@as(i128, @bitCast(@as(u128, 0xffffffff_ffffffff_ffffffff_ffffffff))));
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: u32 = 0; var i: u32 = 0;
while (i < 10_000) : (i += 1) { while (i < 10_000) : (i += 1) {

View file

@ -132,7 +132,7 @@ test "__udivei4/__umodei4" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
var rnd = RndGen.init(42); var rnd = RndGen.init(42);
var i: usize = 10000; var i: usize = 10000;
while (i > 0) : (i -= 1) { while (i > 0) : (i -= 1) {

View file

@ -380,7 +380,7 @@ pub fn shuffleWithIndex(r: Random, comptime T: type, buf: []T, comptime Index: t
/// ///
/// This is useful for selecting an item from a slice where weights are not equal. /// This is useful for selecting an item from a slice where weights are not equal.
/// `T` must be a numeric type capable of holding the sum of `proportions`. /// `T` must be a numeric type capable of holding the sum of `proportions`.
pub fn weightedIndex(r: std.rand.Random, comptime T: type, proportions: []const T) usize { pub fn weightedIndex(r: Random, comptime T: type, proportions: []const T) usize {
// This implementation works by summing the proportions and picking a // This implementation works by summing the proportions and picking a
// random point in [0, sum). We then loop over the proportions, // random point in [0, sum). We then loop over the proportions,
// accumulating until our accumulator is greater than the random point. // accumulating until our accumulator is greater than the random point.

View file

@ -10,7 +10,6 @@
const std = @import("std"); const std = @import("std");
const mem = std.mem; const mem = std.mem;
const Random = std.rand.Random;
const Self = @This(); const Self = @This();
const Ascon = std.crypto.core.Ascon(.little); const Ascon = std.crypto.core.Ascon(.little);
@ -39,9 +38,9 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
self.state.permute(); self.state.permute();
} }
/// Returns a `std.rand.Random` structure backed by the current RNG. /// Returns a `std.Random` structure backed by the current RNG.
pub fn random(self: *Self) Random { pub fn random(self: *Self) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
/// Fills the buffer with random bytes. /// Fills the buffer with random bytes.

View file

@ -5,7 +5,6 @@
const std = @import("std"); const std = @import("std");
const mem = std.mem; const mem = std.mem;
const Random = std.rand.Random;
const Self = @This(); const Self = @This();
const Cipher = std.crypto.stream.chacha.ChaCha8IETF; const Cipher = std.crypto.stream.chacha.ChaCha8IETF;
@ -53,9 +52,9 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
self.refill(); self.refill();
} }
/// Returns a `std.rand.Random` structure backed by the current RNG. /// Returns a `std.Random` structure backed by the current RNG.
pub fn random(self: *Self) Random { pub fn random(self: *Self) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
// Refills the buffer with random bytes, overwriting the previous key. // Refills the buffer with random bytes, overwriting the previous key.

View file

@ -4,7 +4,6 @@
//! https://doc.rust-lang.org/rand/src/rand/prng/isaac64.rs.html //! https://doc.rust-lang.org/rand/src/rand/prng/isaac64.rs.html
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const mem = std.mem; const mem = std.mem;
const Isaac64 = @This(); const Isaac64 = @This();
@ -30,8 +29,8 @@ pub fn init(init_s: u64) Isaac64 {
return isaac; return isaac;
} }
pub fn random(self: *Isaac64) Random { pub fn random(self: *Isaac64) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2: usize) void { fn step(self: *Isaac64, mix: u64, base: usize, comptime m1: usize, comptime m2: usize) void {

View file

@ -3,7 +3,6 @@
//! PRNG //! PRNG
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const Pcg = @This(); const Pcg = @This();
const default_multiplier = 6364136223846793005; const default_multiplier = 6364136223846793005;
@ -21,8 +20,8 @@ pub fn init(init_s: u64) Pcg {
return pcg; return pcg;
} }
pub fn random(self: *Pcg) Random { pub fn random(self: *Pcg) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
fn next(self: *Pcg) u32 { fn next(self: *Pcg) u32 {
@ -37,7 +36,7 @@ fn next(self: *Pcg) u32 {
fn seed(self: *Pcg, init_s: u64) void { fn seed(self: *Pcg, init_s: u64) void {
// Pcg requires 128-bits of seed. // Pcg requires 128-bits of seed.
var gen = std.rand.SplitMix64.init(init_s); var gen = std.Random.SplitMix64.init(init_s);
self.seedTwo(gen.next(), gen.next()); self.seedTwo(gen.next(), gen.next());
} }

View file

@ -3,7 +3,6 @@
// Beware: this PRNG is trivially predictable. While fast, it should *never* be used for cryptographic purposes. // Beware: this PRNG is trivially predictable. While fast, it should *never* be used for cryptographic purposes.
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const math = std.math; const math = std.math;
const RomuTrio = @This(); const RomuTrio = @This();
@ -17,8 +16,8 @@ pub fn init(init_s: u64) RomuTrio {
return x; return x;
} }
pub fn random(self: *RomuTrio) Random { pub fn random(self: *RomuTrio) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
fn next(self: *RomuTrio) u64 { fn next(self: *RomuTrio) u64 {
@ -42,7 +41,7 @@ pub fn seedWithBuf(self: *RomuTrio, buf: [24]u8) void {
pub fn seed(self: *RomuTrio, init_s: u64) void { pub fn seed(self: *RomuTrio, init_s: u64) void {
// RomuTrio requires 192-bits of seed. // RomuTrio requires 192-bits of seed.
var gen = std.rand.SplitMix64.init(init_s); var gen = std.Random.SplitMix64.init(init_s);
self.x_state = gen.next(); self.x_state = gen.next();
self.y_state = gen.next(); self.y_state = gen.next();

View file

@ -3,7 +3,6 @@
//! See http://pracrand.sourceforge.net/ //! See http://pracrand.sourceforge.net/
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const math = std.math; const math = std.math;
const Sfc64 = @This(); const Sfc64 = @This();
@ -23,8 +22,8 @@ pub fn init(init_s: u64) Sfc64 {
return x; return x;
} }
pub fn random(self: *Sfc64) Random { pub fn random(self: *Sfc64) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
fn next(self: *Sfc64) u64 { fn next(self: *Sfc64) u64 {

View file

@ -3,7 +3,6 @@
//! PRNG //! PRNG
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const math = std.math; const math = std.math;
const Xoroshiro128 = @This(); const Xoroshiro128 = @This();
@ -16,8 +15,8 @@ pub fn init(init_s: u64) Xoroshiro128 {
return x; return x;
} }
pub fn random(self: *Xoroshiro128) Random { pub fn random(self: *Xoroshiro128) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
pub fn next(self: *Xoroshiro128) u64 { pub fn next(self: *Xoroshiro128) u64 {
@ -59,7 +58,7 @@ pub fn jump(self: *Xoroshiro128) void {
pub fn seed(self: *Xoroshiro128, init_s: u64) void { pub fn seed(self: *Xoroshiro128, init_s: u64) void {
// Xoroshiro requires 128-bits of seed. // Xoroshiro requires 128-bits of seed.
var gen = std.rand.SplitMix64.init(init_s); var gen = std.Random.SplitMix64.init(init_s);
self.s[0] = gen.next(); self.s[0] = gen.next();
self.s[1] = gen.next(); self.s[1] = gen.next();

View file

@ -3,7 +3,6 @@
//! PRNG //! PRNG
const std = @import("std"); const std = @import("std");
const Random = std.rand.Random;
const math = std.math; const math = std.math;
const Xoshiro256 = @This(); const Xoshiro256 = @This();
@ -18,8 +17,8 @@ pub fn init(init_s: u64) Xoshiro256 {
return x; return x;
} }
pub fn random(self: *Xoshiro256) Random { pub fn random(self: *Xoshiro256) std.Random {
return Random.init(self, fill); return std.Random.init(self, fill);
} }
pub fn next(self: *Xoshiro256) u64 { pub fn next(self: *Xoshiro256) u64 {
@ -57,7 +56,7 @@ pub fn jump(self: *Xoshiro256) void {
pub fn seed(self: *Xoshiro256, init_s: u64) void { pub fn seed(self: *Xoshiro256, init_s: u64) void {
// Xoshiro requires 256-bits of seed. // Xoshiro requires 256-bits of seed.
var gen = std.rand.SplitMix64.init(init_s); var gen = std.Random.SplitMix64.init(init_s);
self.s[0] = gen.next(); self.s[0] = gen.next();
self.s[1] = gen.next(); self.s[1] = gen.next();

View file

@ -4,7 +4,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const time = std.time; const time = std.time;
const Timer = time.Timer; const Timer = time.Timer;
const rand = std.rand; const Random = std.Random;
const KiB = 1024; const KiB = 1024;
const MiB = 1024 * KiB; const MiB = 1024 * KiB;
@ -19,32 +19,32 @@ const Rng = struct {
const prngs = [_]Rng{ const prngs = [_]Rng{
Rng{ Rng{
.ty = rand.Isaac64, .ty = Random.Isaac64,
.name = "isaac64", .name = "isaac64",
.init_u64 = 0, .init_u64 = 0,
}, },
Rng{ Rng{
.ty = rand.Pcg, .ty = Random.Pcg,
.name = "pcg", .name = "pcg",
.init_u64 = 0, .init_u64 = 0,
}, },
Rng{ Rng{
.ty = rand.RomuTrio, .ty = Random.RomuTrio,
.name = "romutrio", .name = "romutrio",
.init_u64 = 0, .init_u64 = 0,
}, },
Rng{ Rng{
.ty = std.rand.Sfc64, .ty = Random.Sfc64,
.name = "sfc64", .name = "sfc64",
.init_u64 = 0, .init_u64 = 0,
}, },
Rng{ Rng{
.ty = std.rand.Xoroshiro128, .ty = Random.Xoroshiro128,
.name = "xoroshiro128", .name = "xoroshiro128",
.init_u64 = 0, .init_u64 = 0,
}, },
Rng{ Rng{
.ty = std.rand.Xoshiro256, .ty = Random.Xoshiro256,
.name = "xoshiro256", .name = "xoshiro256",
.init_u64 = 0, .init_u64 = 0,
}, },
@ -52,12 +52,12 @@ const prngs = [_]Rng{
const csprngs = [_]Rng{ const csprngs = [_]Rng{
Rng{ Rng{
.ty = rand.Ascon, .ty = Random.Ascon,
.name = "ascon", .name = "ascon",
.init_u8s = &[_]u8{0} ** 32, .init_u8s = &[_]u8{0} ** 32,
}, },
Rng{ Rng{
.ty = rand.ChaCha, .ty = Random.ChaCha,
.name = "chacha", .name = "chacha",
.init_u8s = &[_]u8{0} ** 32, .init_u8s = &[_]u8{0} ** 32,
}, },

View file

@ -10,7 +10,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const builtin = @import("builtin"); const builtin = @import("builtin");
const math = std.math; const math = std.math;
const Random = std.rand.Random; const Random = std.Random;
pub fn next_f64(random: Random, comptime tables: ZigTable) f64 { pub fn next_f64(random: Random, comptime tables: ZigTable) f64 {
while (true) { while (true) {
@ -127,7 +127,7 @@ pub fn norm_zero_case(random: Random, u: f64) f64 {
} }
test "normal dist sanity" { test "normal dist sanity" {
var prng = std.rand.DefaultPrng.init(0); var prng = Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
var i: usize = 0; var i: usize = 0;
@ -156,7 +156,7 @@ pub fn exp_zero_case(random: Random, _: f64) f64 {
} }
test "exp dist smoke test" { test "exp dist smoke test" {
var prng = std.rand.DefaultPrng.init(0); var prng = Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
var i: usize = 0; var i: usize = 0;

View file

@ -328,7 +328,7 @@ test "RwLock - concurrent access" {
} }
fn writer(self: *Self, thread_idx: usize) !void { fn writer(self: *Self, thread_idx: usize) !void {
var prng = std.rand.DefaultPrng.init(thread_idx); var prng = std.Random.DefaultPrng.init(thread_idx);
var rnd = prng.random(); var rnd = prng.random();
while (true) { while (true) {

View file

@ -10,7 +10,7 @@ const crypto = std.crypto;
const KiB = 1024; const KiB = 1024;
const MiB = 1024 * KiB; const MiB = 1024 * KiB;
var prng = std.rand.DefaultPrng.init(0); var prng = std.Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
const Crypto = struct { const Crypto = struct {

View file

@ -110,7 +110,7 @@ const assert = std.debug.assert;
const crypto = std.crypto; const crypto = std.crypto;
const math = std.math; const math = std.math;
const mem = std.mem; const mem = std.mem;
const RndGen = std.rand.DefaultPrng; const RndGen = std.Random.DefaultPrng;
const sha3 = crypto.hash.sha3; const sha3 = crypto.hash.sha3;
// Q is the parameter q 3329 = 2¹¹ + 2¹ + 2 + 1. // Q is the parameter q 3329 = 2¹¹ + 2¹ + 2 + 1.

View file

@ -10,7 +10,7 @@ const os = std.os;
/// We use this as a layer of indirection because global const pointers cannot /// We use this as a layer of indirection because global const pointers cannot
/// point to thread-local variables. /// point to thread-local variables.
pub const interface = std.rand.Random{ pub const interface = std.Random{
.ptr = undefined, .ptr = undefined,
.fillFn = tlsCsprngFill, .fillFn = tlsCsprngFill,
}; };
@ -43,7 +43,7 @@ const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{
}) orelse true; }) orelse true;
const is_haiku = builtin.os.tag == .haiku; const is_haiku = builtin.os.tag == .haiku;
const Rng = std.rand.DefaultCsprng; const Rng = std.Random.DefaultCsprng;
const Context = struct { const Context = struct {
init_state: enum(u8) { uninitialized = 0, initialized, failed }, init_state: enum(u8) { uninitialized = 0, initialized, failed },

View file

@ -10,7 +10,7 @@ const KiB = 1024;
const MiB = 1024 * KiB; const MiB = 1024 * KiB;
const GiB = 1024 * MiB; const GiB = 1024 * MiB;
var prng = std.rand.DefaultPrng.init(0); var prng = std.Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
const Hash = struct { const Hash = struct {

View file

@ -1884,7 +1884,7 @@ test "std.hash_map put and remove loop in random order" {
while (i < size) : (i += 1) { while (i < size) : (i += 1) {
try keys.append(i); try keys.append(i);
} }
var prng = std.rand.DefaultPrng.init(0); var prng = std.Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
while (i < iterations) : (i += 1) { while (i < iterations) : (i += 1) {
@ -1916,7 +1916,7 @@ test "std.hash_map remove one million elements in random order" {
keys.append(i) catch unreachable; keys.append(i) catch unreachable;
} }
var prng = std.rand.DefaultPrng.init(0); var prng = std.Random.DefaultPrng.init(0);
const random = prng.random(); const random = prng.random();
random.shuffle(u32, keys.items); random.shuffle(u32, keys.items);

View file

@ -250,7 +250,7 @@ test "ArenaAllocator (reset with preheating)" {
var arena_allocator = ArenaAllocator.init(std.testing.allocator); var arena_allocator = ArenaAllocator.init(std.testing.allocator);
defer arena_allocator.deinit(); defer arena_allocator.deinit();
// provides some variance in the allocated data // provides some variance in the allocated data
var rng_src = std.rand.DefaultPrng.init(19930913); var rng_src = std.Random.DefaultPrng.init(19930913);
const random = rng_src.random(); const random = rng_src.random();
var rounds: usize = 25; var rounds: usize = 25;
while (rounds > 0) { while (rounds > 0) {

View file

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
const io = std.io; const io = std.io;
const DefaultPrng = std.rand.DefaultPrng; const DefaultPrng = std.Random.DefaultPrng;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
const expectError = std.testing.expectError; const expectError = std.testing.expectError;

View file

@ -594,7 +594,7 @@ test "big.rational toFloat" {
test "big.rational set/to Float round-trip" { test "big.rational set/to Float round-trip" {
var a = try Rational.init(testing.allocator); var a = try Rational.init(testing.allocator);
defer a.deinit(); defer a.deinit();
var prng = std.rand.DefaultPrng.init(0x5EED); var prng = std.Random.DefaultPrng.init(0x5EED);
const random = prng.random(); const random = prng.random();
var i: usize = 0; var i: usize = 0;
while (i < 512) : (i += 1) { while (i < 512) : (i += 1) {

View file

@ -4423,7 +4423,7 @@ test "read/write(Var)PackedInt" {
const foreign_endian: Endian = if (native_endian == .big) .little else .big; const foreign_endian: Endian = if (native_endian == .big) .little else .big;
const expect = std.testing.expect; const expect = std.testing.expect;
var prng = std.rand.DefaultPrng.init(1234); var prng = std.Random.DefaultPrng.init(1234);
const random = prng.random(); const random = prng.random();
@setEvalBranchQuota(10_000); @setEvalBranchQuota(10_000);

View file

@ -866,7 +866,7 @@ test "std.PriorityDequeue: shrinkAndFree" {
} }
test "std.PriorityDequeue: fuzz testing min" { test "std.PriorityDequeue: fuzz testing min" {
var prng = std.rand.DefaultPrng.init(0x12345678); var prng = std.Random.DefaultPrng.init(0x12345678);
const random = prng.random(); const random = prng.random();
const test_case_count = 100; const test_case_count = 100;
@ -878,7 +878,7 @@ test "std.PriorityDequeue: fuzz testing min" {
} }
} }
fn fuzzTestMin(rng: std.rand.Random, comptime queue_size: usize) !void { fn fuzzTestMin(rng: std.Random, comptime queue_size: usize) !void {
const allocator = testing.allocator; const allocator = testing.allocator;
const items = try generateRandomSlice(allocator, rng, queue_size); const items = try generateRandomSlice(allocator, rng, queue_size);
@ -895,7 +895,7 @@ fn fuzzTestMin(rng: std.rand.Random, comptime queue_size: usize) !void {
} }
test "std.PriorityDequeue: fuzz testing max" { test "std.PriorityDequeue: fuzz testing max" {
var prng = std.rand.DefaultPrng.init(0x87654321); var prng = std.Random.DefaultPrng.init(0x87654321);
const random = prng.random(); const random = prng.random();
const test_case_count = 100; const test_case_count = 100;
@ -907,7 +907,7 @@ test "std.PriorityDequeue: fuzz testing max" {
} }
} }
fn fuzzTestMax(rng: std.rand.Random, queue_size: usize) !void { fn fuzzTestMax(rng: std.Random, queue_size: usize) !void {
const allocator = testing.allocator; const allocator = testing.allocator;
const items = try generateRandomSlice(allocator, rng, queue_size); const items = try generateRandomSlice(allocator, rng, queue_size);
@ -924,7 +924,7 @@ fn fuzzTestMax(rng: std.rand.Random, queue_size: usize) !void {
} }
test "std.PriorityDequeue: fuzz testing min and max" { test "std.PriorityDequeue: fuzz testing min and max" {
var prng = std.rand.DefaultPrng.init(0x87654321); var prng = std.Random.DefaultPrng.init(0x87654321);
const random = prng.random(); const random = prng.random();
const test_case_count = 100; const test_case_count = 100;
@ -936,7 +936,7 @@ test "std.PriorityDequeue: fuzz testing min and max" {
} }
} }
fn fuzzTestMinMax(rng: std.rand.Random, queue_size: usize) !void { fn fuzzTestMinMax(rng: std.Random, queue_size: usize) !void {
const allocator = testing.allocator; const allocator = testing.allocator;
const items = try generateRandomSlice(allocator, rng, queue_size); const items = try generateRandomSlice(allocator, rng, queue_size);
@ -963,7 +963,7 @@ fn fuzzTestMinMax(rng: std.rand.Random, queue_size: usize) !void {
} }
} }
fn generateRandomSlice(allocator: std.mem.Allocator, rng: std.rand.Random, size: usize) ![]u32 { fn generateRandomSlice(allocator: std.mem.Allocator, rng: std.Random, size: usize) ![]u32 {
var array = std.ArrayList(u32).init(allocator); var array = std.ArrayList(u32).init(allocator);
try array.ensureTotalCapacity(size); try array.ensureTotalCapacity(size);

View file

@ -379,7 +379,7 @@ test "sort with context in the middle of a slice" {
} }
test "sort fuzz testing" { test "sort fuzz testing" {
var prng = std.rand.DefaultPrng.init(0x12345678); var prng = std.Random.DefaultPrng.init(0x12345678);
const random = prng.random(); const random = prng.random();
const test_case_count = 10; const test_case_count = 10;

View file

@ -18,7 +18,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
/// A customized pseudo random number generator for the treap. /// A customized pseudo random number generator for the treap.
/// This just helps reducing the memory size of the treap itself /// This just helps reducing the memory size of the treap itself
/// as std.rand.DefaultPrng requires larger state (while producing better entropy for randomness to be fair). /// as std.Random.DefaultPrng requires larger state (while producing better entropy for randomness to be fair).
const Prng = struct { const Prng = struct {
xorshift: usize = 0, xorshift: usize = 0,
@ -305,7 +305,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
// https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-array-exactly-once-in-random-order/ // https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-array-exactly-once-in-random-order/
fn SliceIterRandomOrder(comptime T: type) type { fn SliceIterRandomOrder(comptime T: type) type {
return struct { return struct {
rng: std.rand.Random, rng: std.Random,
slice: []T, slice: []T,
index: usize = undefined, index: usize = undefined,
offset: usize = undefined, offset: usize = undefined,
@ -313,7 +313,7 @@ fn SliceIterRandomOrder(comptime T: type) type {
const Self = @This(); const Self = @This();
pub fn init(slice: []T, rng: std.rand.Random) Self { pub fn init(slice: []T, rng: std.Random) Self {
return Self{ return Self{
.rng = rng, .rng = rng,
.slice = slice, .slice = slice,
@ -353,7 +353,7 @@ test "std.Treap: insert, find, replace, remove" {
var treap = TestTreap{}; var treap = TestTreap{};
var nodes: [10]TestNode = undefined; var nodes: [10]TestNode = undefined;
var prng = std.rand.DefaultPrng.init(0xdeadbeef); var prng = std.Random.DefaultPrng.init(0xdeadbeef);
var iter = SliceIterRandomOrder(TestNode).init(&nodes, prng.random()); var iter = SliceIterRandomOrder(TestNode).init(&nodes, prng.random());
// insert check // insert check

View file

@ -136,7 +136,7 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
var more_fixups: Ast.Fixups = .{}; var more_fixups: Ast.Fixups = .{};
defer more_fixups.deinit(gpa); defer more_fixups.deinit(gpa);
var rng = std.rand.DefaultPrng.init(seed); var rng = std.Random.DefaultPrng.init(seed);
// 1. Walk the AST of the source file looking for independent // 1. Walk the AST of the source file looking for independent
// reductions and collecting them all into an array list. // reductions and collecting them all into an array list.
@ -274,7 +274,7 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
return std.process.cleanExit(); return std.process.cleanExit();
} }
fn sortTransformations(transformations: []Walk.Transformation, rng: std.rand.Random) void { fn sortTransformations(transformations: []Walk.Transformation, rng: std.Random) void {
rng.shuffle(Walk.Transformation, transformations); rng.shuffle(Walk.Transformation, transformations);
// Stable sort based on priority to keep randomness as the secondary sort. // Stable sort based on priority to keep randomness as the secondary sort.
// TODO: introduce transformation priorities // TODO: introduce transformation priorities

View file

@ -3356,7 +3356,7 @@ test "StringTable" {
} }
break :ids buf; break :ids buf;
}; };
var prng = std.rand.DefaultPrng.init(0); var prng = std.Random.DefaultPrng.init(0);
var random = prng.random(); var random = prng.random();
random.shuffle(u16, &ids); random.shuffle(u16, &ids);