Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonRandom.adoc
1 MLtonRandom
2 ===========
3
4 [source,sml]
5 ----
6 signature MLTON_RANDOM =
7 sig
8 val alphaNumChar: unit -> char
9 val alphaNumString: int -> string
10 val rand: unit -> word
11 val seed: unit -> word option
12 val srand: word -> unit
13 val useed: unit -> word option
14 end
15 ----
16
17 * `alphaNumChar ()`
18 +
19 returns a random alphanumeric character.
20
21 * `alphaNumString n`
22 +
23 returns a string of length `n` of random alphanumeric characters.
24
25 * `rand ()`
26 +
27 returns the next pseudo-random number.
28
29 * `seed ()`
30 +
31 returns a random word from `/dev/random`. Useful as an arg to
32 `srand`. If `/dev/random` can not be read from, `seed ()` returns
33 `NONE`. A call to `seed` may block until enough random bits are
34 available.
35
36 * `srand w`
37 +
38 sets the seed used by `rand` to `w`.
39
40 * `useed ()`
41 +
42 returns a random word from `/dev/urandom`. Useful as an arg to
43 `srand`. If `/dev/urandom` can not be read from, `useed ()` returns
44 `NONE`. A call to `useed` will never block -- it will instead return
45 lower quality random bits.