11module [
22 IOErr ,
3- seed!,
3+ random_u64!,
4+ random_u32!,
5+ random_bytes!,
46]
57
68import InternalIOErr
@@ -13,8 +15,45 @@ import Host
1315IOErr : InternalIOErr . IOErr
1416
1517## Generate a random U64 using the system's source of randomness.
16- ## This uses the Rust crate `getrandom`.
17- seed ! : {} => Result U64 [RandomErr IOErr ]
18- seed ! = |{}|
19- Host . random_seed !({})
18+ ##
19+ ## This uses Rust's [getrandom](https://crates.io/crates/getrandom) crate to produce
20+ ## a single random 64-bit integer. Note that this is a direct interface to the
21+ ## system's source of randomness, meaning that each call introduces a significant
22+ ## amount of overhead. If you need to generate a lot of random numbers, consider
23+ ## calling this function once to generate a single "seed", then using a library
24+ ## such as [roc-random](https://github.com/lukewilliamboswell/roc-random) to generate
25+ ## additional random numbers.
26+ ##
27+ ## > Note that 64 bits is NOT considered sufficient randomness for cryptographic
28+ ## applications such as encryption keys. Prefer using `random_bytes()` to generate
29+ ## larger random values for security-sensitive applications.
30+ random_u64 ! : {} => Result U64 [RandomErr IOErr ]
31+ random_u64 ! = |{}|
32+ Host . random_u64 !({})
33+ |> Result . map_err (|err | RandomErr (InternalIOErr . handle_err (err )))
34+
35+ ## Generate a random U32 using the system's source of randomness.
36+ ##
37+ ## This uses Rust's [getrandom](https://crates.io/crates/getrandom) crate to produce
38+ ## a single random 32-bit integer. Note that this is a direct interface to the
39+ ## system's source of randomness, meaning that each call introduces a significant
40+ ## amount of overhead. If you need to generate a lot of random numbers, consider
41+ ## calling this function once to generate a single "seed", then using a library
42+ ## such as [roc-random](https://github.com/lukewilliamboswell/roc-random) to generate
43+ ## additional random numbers.
44+ ##
45+ ## > Note that 32 bits is NOT considered sufficient randomness for cryptographic
46+ ## applications such as encryption keys. Prefer using `random_bytes()` to generate
47+ ## larger random values for security-sensitive applications.
48+ random_u32 ! : {} => Result U32 [RandomErr IOErr ]
49+ random_u32 ! = |{}|
50+ Host . random_u32 !({})
51+ |> Result . map_err (|err | RandomErr (InternalIOErr . handle_err (err )))
52+
53+ ## Generate an arbitrary number of bytes using the system's source of randomness.
54+ ## For additional details on the specific source of randomness used on various
55+ ## platforms, see the Rust crate [getrandom](https://docs.rs/getrandom/0.3.3/getrandom/index.html).
56+ random_bytes ! : U64 => Result (List U8 ) [RandomErr IOErr ]
57+ random_bytes ! = |count|
58+ Host . random_bytes !(count )
2059 |> Result . map_err (|err | RandomErr (InternalIOErr . handle_err (err )))
0 commit comments