1Random(3) OCaml library Random(3)
2
3
4
6 Random - Pseudo-random number generators (PRNG).
7
9 Module Random
10
12 Module Random
13 : sig end
14
15
16 Pseudo-random number generators (PRNG).
17
18
19
20
21
22
23
24
25 === Basic functions ===
26
27
28 val init : int -> unit
29
30 Initialize the generator, using the argument as a seed. The same seed
31 will always yield the same sequence of numbers.
32
33
34
35
36 val full_init : int array -> unit
37
38 Same as Random.init but takes more data as seed.
39
40
41
42
43 val self_init : unit -> unit
44
45 Initialize the generator with a more-or-less random seed chosen in a
46 system-dependent way.
47
48
49
50
51 val bits : unit -> int
52
53 Return 30 random bits in a nonnegative integer.
54
55
56
57
58 val int : int -> int
59
60
61 Random.int bound returns a random integer between 0 (inclusive) and
62 bound (exclusive). bound must be greater than 0 and less than 2^{30.
63
64
65
66
67 val int32 : Int32.t -> Int32.t
68
69
70 Random.int32 bound returns a random integer between 0 (inclusive) and
71 bound (exclusive). bound must be greater than 0.
72
73
74
75
76 val nativeint : Nativeint.t -> Nativeint.t
77
78
79 Random.nativeint bound returns a random integer between 0 (inclusive)
80 and bound (exclusive). bound must be greater than 0.
81
82
83
84
85 val int64 : Int64.t -> Int64.t
86
87
88 Random.int64 bound returns a random integer between 0 (inclusive) and
89 bound (exclusive). bound must be greater than 0.
90
91
92
93
94 val float : float -> float
95
96
97 Random.float bound returns a random floating-point number between 0
98 (inclusive) and bound (exclusive). If bound is negative, the result is
99 negative or zero. If bound is 0, the result is 0.
100
101
102
103
104 val bool : unit -> bool
105
106
107 Random.bool () returns true or false with probability 0.5 each.
108
109
110
111
112
113 === Advanced functions ===
114
115
116 === The functions from module State manipulate the current state of the
117 random generator explicitely. This allows using one or several deter‐
118 ministic PRNGs, even in a multi-threaded program, without interference
119 from other parts of the program. ===
120
121
122 module State : sig end
123
124
125
126
127
128 val get_state : unit -> State.t
129
130 Return the current state of the generator used by the basic functions.
131
132
133
134
135 val set_state : State.t -> unit
136
137 Set the state of the generator used by the basic functions.
138
139
140
141
142
143
144OCamldoc 2017-03-22 Random(3)