I'd like to generate some random numbers, so I looked around and found roc-random. It doesn't help you with seeding the RNG though, so I figured I could just pull a few bytes from /dev/urandom
, but I'm not sure how to do that.
File.read_bytes!
wants to read until EOF, which wouldn't work with /dev/urandom
.
I see File.open_reader!
, but the only function that accepts a Reader
seems to be File.read_line!
. Technically I guess that would work, since /dev/urandom
will probably yield a \n
byte before too long, but I feel like there's probably a better way?
This totally could be a gap in the basic cli api
I mean it probably should have a random seed generating function in general
Yeah a proper "system random" function would be great b/c it could abstract away the cross-platform details.
Is the basic-cli platform going to stay in Rust? I'd be happy to contribute a PR if that seems worthwhile, I'm certainly not a expert but it's basically a matter of pulling in a crate and wiring up a function or two
Thanks @Joseph Montanaro, a PR would be great, if you provide claude code or codex with the changes from https://github.com/roc-lang/basic-cli/pull/380/files as an example, it will likely be able to take care of the whole thing.
Is the basic-cli platform going to stay in Rust?
I believe Richard wanted to port it to zig but I don't see a problem with adding random support in Rust for now.
Thanks! Should it go in an existing module, or get its own? The only module it sort of fits with would be Env
, I guess? But it's not a great fit even there. Seems a little weird to have a whole module just for one function, but that's how Sleep
is, after all.
I think another module is ok. We might find additional functionality we want in future.
Last updated: Oct 18 2025 at 12:13 UTC