Skip to content

Turn std.rand.Random into a Mixin #3785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/std/atomic/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn startPuts(ctx: *Context) u8 {
var r = std.rand.DefaultPrng.init(0xdeadbeef);
while (put_count != 0) : (put_count -= 1) {
std.time.sleep(1); // let the os scheduler be our fuzz
const x = @bitCast(i32, r.random.scalar(u32));
const x = r.int(i32);
const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
node.* = Queue(i32).Node{
.prev = undefined,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/atomic/stack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn startPuts(ctx: *Context) u8 {
var r = std.rand.DefaultPrng.init(0xdeadbeef);
while (put_count != 0) : (put_count -= 1) {
std.time.sleep(1); // let the os scheduler be our fuzz
const x = @bitCast(i32, r.random.scalar(u32));
const x = r.int(i32);
const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
node.* = Stack(i32).Node{
.next = undefined,
Expand Down
10 changes: 5 additions & 5 deletions lib/std/crypto/benchmark.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn benchmarkHash(comptime Hash: var, comptime bytes: comptime_int) !u64 {
var h = Hash.init();

var block: [Hash.digest_length]u8 = undefined;
prng.random.bytes(block[0..]);
prng.bytes(block[0..]);

var offset: usize = 0;
var timer = try Timer.start();
Expand All @@ -58,10 +58,10 @@ pub fn benchmarkMac(comptime Mac: var, comptime bytes: comptime_int) !u64 {
std.debug.assert(32 >= Mac.mac_length and 32 >= Mac.minimum_key_length);

var in: [1 * MiB]u8 = undefined;
prng.random.bytes(in[0..]);
prng.bytes(in[0..]);

var key: [32]u8 = undefined;
prng.random.bytes(key[0..]);
prng.bytes(key[0..]);

var offset: usize = 0;
var timer = try Timer.start();
Expand All @@ -83,10 +83,10 @@ pub fn benchmarkKeyExchange(comptime DhKeyExchange: var, comptime exchange_count
std.debug.assert(DhKeyExchange.minimum_key_length >= DhKeyExchange.secret_length);

var in: [DhKeyExchange.minimum_key_length]u8 = undefined;
prng.random.bytes(in[0..]);
prng.bytes(in[0..]);

var out: [DhKeyExchange.minimum_key_length]u8 = undefined;
prng.random.bytes(out[0..]);
prng.bytes(out[0..]);

var offset: usize = 0;
var timer = try Timer.start();
Expand Down
4 changes: 2 additions & 2 deletions lib/std/hash/benchmark.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn benchmarkHash(comptime H: var, bytes: usize) !Result {
};

var block: [block_size]u8 = undefined;
prng.random.bytes(block[0..]);
prng.bytes(block[0..]);

var offset: usize = 0;
var timer = try Timer.start();
Expand All @@ -122,7 +122,7 @@ pub fn benchmarkHash(comptime H: var, bytes: usize) !Result {
pub fn benchmarkHashSmallKeys(comptime H: var, key_size: usize, bytes: usize) !Result {
const key_count = bytes / key_size;
var block: [block_size]u8 = undefined;
prng.random.bytes(block[0..]);
prng.bytes(block[0..]);

var i: usize = 0;
var timer = try Timer.start();
Expand Down
2 changes: 1 addition & 1 deletion lib/std/io/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test "write a file, read it, then delete it" {

var data: [1024]u8 = undefined;
var prng = DefaultPrng.init(1234);
prng.random.bytes(data[0..]);
prng.bytes(data[0..]);
const tmp_file_name = "temp_test_file.txt";
{
var file = try File.openWrite(tmp_file_name);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/big/rational.zig
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ test "big.rational set/to Float round-trip" {
var prng = std.rand.DefaultPrng.init(0x5EED);
var i: usize = 0;
while (i < 512) : (i += 1) {
const r = prng.random.float(f64);
const r = prng.float(f64);
try a.setFloat(f64, r);
testing.expect((try a.toFloat(f64)) == r);
}
Expand Down
Loading