#Compiler won't recognize std.rand

1 messages · Page 1 of 1 (latest)

strong yarrow
#

Hi, I'm very new to zig and having a small issue generating random numbers. I'm getting an error where std.rand is not recognized

const std = @import("std");
const math = std.math;
const rand = std.rand;

pub fn main() void {
    const rng = rand.DefaultPrng.init(123456789);
    // ...
}```

run
└─ run zigThingsAreHappening
└─ zig build-exe zigThingsAreHappening Debug native 1 errors
src\main.zig:3:17: error: root source file struct 'std' has no member named 'rand'
const rand = std.rand;
~^~~```

Hope someone can help, thanks!

quasi nova
#

There are no std.rand, only std.Random

strong yarrow
#

Is rand deprecated or is there just misinfo online?

#

That did work so thanks

quasi nova
#

I think it is just deprecated

forest radish
#

the namespace was collapsed, everything in std.rand was moved into std.Random

quasi nova
#

Now the whole random is under std.Random interface

#

this works:

    const rng = std.Random.DefaultPrng.init(123456789);
    var rand = rng.random();
    std.debug.print("{any}", .{rand.int(i32)});