1+ module [
2+ IOErr ,
3+ random_seed_u64!,
4+ random_seed_u32!,
5+ ]
6+
7+ import InternalIOErr
8+ import Host
9+
10+
11+ ## Tag union of possible errors when getting a random seed.
12+ ##
13+ ## > This is the same as [`File.IOErr`](File#IOErr).
14+ IOErr : InternalIOErr . IOErr
15+
16+ ## Generate a random `U64` seed using the system's source of randomness.
17+ ## A "seed" is a starting value used to deterministically generate a random sequence.
18+ ##
19+ ## > !! This function is NOT cryptographically secure.
20+ ##
21+ ## This uses the [`u64()`](https://docs.rs/getrandom/latest/getrandom/fn.u64.html) function
22+ ## of the [getrandom crate](https://crates.io/crates/getrandom) to produce
23+ ## a single random 64-bit integer.
24+ ##
25+ ## For hobby purposes, you can just call this function repreatedly to get random numbers.
26+ ## In general, we recommend using this seed in combination with a library like
27+ ## [roc-random](https://github.com/lukewilliamboswell/roc-random) to generate additional
28+ ## random numbers quickly.
29+ ##
30+ random_seed_u64 ! : {} => Result U64 [RandomErr IOErr ]
31+ random_seed_u64 ! = |{}|
32+ Host . random_u64 !({})
33+ |> Result . map_err (|err | RandomErr (InternalIOErr . handle_err (err )))
34+
35+ ## Generate a random `U32` seed using the system's source of randomness.
36+ ## A "seed" is a starting value used to deterministically generate a random sequence.
37+ ##
38+ ## > !! This function is NOT cryptographically secure.
39+ ##
40+ ## This uses the [`u32()`](https://docs.rs/getrandom/0.3.3/getrandom/fn.u32.html) function
41+ ## of the [getrandom crate](https://crates.io/crates/getrandom) to produce
42+ ## a single random 32-bit integer.
43+ ##
44+ ## For hobby purposes, you can just call this function repreatedly to get random numbers.
45+ ## In general, we recommend using this seed in combination with a library like
46+ ## [roc-random](https://github.com/lukewilliamboswell/roc-random) to generate additional
47+ ## random numbers quickly.
48+ ##
49+ random_seed_u32 ! : {} => Result U32 [RandomErr IOErr ]
50+ random_seed_u32 ! = |{}|
51+ Host . random_u32 !({})
52+ |> Result . map_err (|err | RandomErr (InternalIOErr . handle_err (err )))
0 commit comments