Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonRandom.adoc
CommitLineData
7f918cf1
CE
1MLtonRandom
2===========
3
4[source,sml]
5----
6signature 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+
19returns a random alphanumeric character.
20
21* `alphaNumString n`
22+
23returns a string of length `n` of random alphanumeric characters.
24
25* `rand ()`
26+
27returns the next pseudo-random number.
28
29* `seed ()`
30+
31returns 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
34available.
35
36* `srand w`
37+
38sets the seed used by `rand` to `w`.
39
40* `useed ()`
41+
42returns 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
45lower quality random bits.