MLton.Random.seed
Stephen Weeks
MLton@sourcelight.com
Mon, 25 Jun 2001 19:40:38 -0700
What is correct failure mode for MLton.Random.{seed,useed} when they are unable
to read 4 bytes from /dev/random? Right now, they are implemented as follows,
and raise Fail if they are unable to read 4 bytes.
(* Linux specific. Uses /dev/random and /dev/urandom to get a
* random word.
*)
local
fun make (file, name) () =
let
val buf = Word8Array.array (4, 0w0)
val fd =
let
open Posix.FileSys
in
openf (file, O_RDONLY, O.flags [])
end
val n = Posix.IO.readArr (fd, {buf = buf, i = 0, sz = SOME 4})
val _ = Posix.IO.close fd
val _ =
if 4 = n
then ()
else raise Fail name
in
Pack32Little.subArr (buf, 0)
end
in
val seed = make ("/dev/random", "Random.seed")
val useed = make ("/dev/urandom", "Random.useed")
end