ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.81k stars 2.55k forks source link

std.rand.DefaultPrng does not fail #21427

Closed JJ closed 1 month ago

JJ commented 1 month ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

This function:

const std = @import("std");
const expect = std.testing.expect;

// Random number generator used all over
pub fn ourRng() !std.rand.DefaultPrng {
    return std.rand.DefaultPrng.init(blk: {
        var seed: u64 = undefined;
        try std.posix.getrandom(std.mem.asBytes(&seed));
        break :blk seed;
    });
}

// test the generator
test "random generators" {
    var first_rng = try ourRng();
    for (1..10) |_| {
        var second_rng = try ourRng();
        try expect(first_rng.random().int(i32) != second_rng.random().int(i32));
        first_rng = second_rng;
    }
}

Compiles and works. However, when trying to use the generated object, it fails with:

Expected Behavior

std.rand.DefaultPrng seems to be absent from the documentation, thus deprecated, substituted by std.Random.DefaultPrng It should fail or warn about deprecation.

nektro commented 1 month ago

Zig does not have warnings. the alias from rand to Random was removed after 0.13.0 was tagged and does error in master branch

fixed in https://github.com/ziglang/zig/commit/76fb2b685b202ea665b850338e353c7816f5b2bb