def random_bytes
import bend-collections-laws-crypto@1.0.0.0/src/crypto/password.bend as Passwordimport Base
90# n bytes from the operating system's generator.
91def random_bytes(n: Nat) -> IO(List<&2, U32>):
92 match n:
93 case 0n:
94 IO.pure(List<&2, U32>, Nil{})
95 case 1n+k:
96 do IO<List<&2, U32>>:
97 w : U32 <- IO.try(U32, IO.random_u32())
98 rest : List<&2, U32> <- random_bytes(k)
99 return U32.and(w, 255) <> rest