A library to generate random numbers for cryptographic applications in OCaml. It relies on the rand Rust library.
You'll need Rust: https://rustup.rs/
Then:
$ opam install randomlOr if you have esy:
{
"dependencies": {
+ "@opam/randoml": "*"
},
}Fill a buffer with random bytes:
let buf = Bytes.create 16 in
rand_fill bufGet a random int32:
let x = rand_int32 ()Get a random int64:
let x = rand_int64 ()Get a random int32 between 1 and 100000000:
let lower = Int32.of_int_exn 1 in
let upper = Int32.of_int_exn 100000000 in
let x = rand_int32_range lower upperGet a random int64 between 1 and 100000000:
let lower = Int64.of_int_exn 1 in
let upper = Int64.of_int_exn 100000000 in
let x = rand_int64_range lower upperGet a random Bigint upperbounded by some number (warning: it won't work well if your upperbound is not smaller and close to a power of 2):
let upperbound =
Bigint.of_string
"7067388259113537318333190002971674063309935587502475832486424805170478604"
in
let x = rand_bigint upperboundAs opam installs dependencies in a sandbox, rust dependencies need to be vendored via cargo vendor.
Thus, this command needs to be executed every time there's a change in the Cargo.lock file.