1Stdlib.Random(3) OCaml library Stdlib.Random(3)
2
3
4
6 Stdlib.Random - no description
7
9 Module Stdlib.Random
10
12 Module Random
13 : (module Stdlib__Random)
14
15
16
17
18
19
20
21
22
23 Basic functions
24 val init : int -> unit
25
26 Initialize the domain-local generator, using the argument as a seed.
27 The same seed will always yield the same sequence of numbers.
28
29
30
31 val full_init : int array -> unit
32
33 Same as Random.init but takes more data as seed.
34
35
36
37 val self_init : unit -> unit
38
39 Initialize the domain-local generator with a random seed chosen in a
40 system-dependent way. If /dev/urandom is available on the host ma‐
41 chine, it is used to provide a highly random initial seed. Otherwise,
42 a less random seed is computed from system parameters (current time,
43 process IDs, domain-local state).
44
45
46
47 val bits : unit -> int
48
49 Return 30 random bits in a nonnegative integer.
50
51
52 Before5.0.0 used a different algorithm (affects all the following func‐
53 tions)
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 val full_int : int -> int
67
68
69 Random.full_int bound returns a random integer between 0 (inclusive)
70 and bound (exclusive). bound may be any positive integer.
71
72 If bound is less than 2^30, Random.full_int bound is equal to Ran‐
73 dom.int bound . If bound is greater than 2^30 (on 64-bit systems or
74 non-standard environments, such as JavaScript), Random.full_int returns
75 a value, where Random.int raises Invalid_argument .
76
77
78 Since 4.13.0
79
80
81
82 val int32 : Int32.t -> Int32.t
83
84
85 Random.int32 bound returns a random integer between 0 (inclusive) and
86 bound (exclusive). bound must be greater than 0.
87
88
89
90 val nativeint : Nativeint.t -> Nativeint.t
91
92
93 Random.nativeint bound returns a random integer between 0 (inclusive)
94 and bound (exclusive). bound must be greater than 0.
95
96
97
98 val int64 : Int64.t -> Int64.t
99
100
101 Random.int64 bound returns a random integer between 0 (inclusive) and
102 bound (exclusive). bound must be greater than 0.
103
104
105
106 val float : float -> float
107
108
109 Random.float bound returns a random floating-point number between 0 and
110 bound (inclusive). If bound is negative, the result is negative or
111 zero. If bound is 0, the result is 0.
112
113
114
115 val bool : unit -> bool
116
117
118 Random.bool () returns true or false with probability 0.5 each.
119
120
121
122 val bits32 : unit -> Int32.t
123
124
125 Random.bits32 () returns 32 random bits as an integer between
126 Int32.min_int and Int32.max_int .
127
128
129 Since 4.14.0
130
131
132
133 val bits64 : unit -> Int64.t
134
135
136 Random.bits64 () returns 64 random bits as an integer between
137 Int64.min_int and Int64.max_int .
138
139
140 Since 4.14.0
141
142
143
144 val nativebits : unit -> Nativeint.t
145
146
147 Random.nativebits () returns 32 or 64 random bits (depending on the bit
148 width of the platform) as an integer between Nativeint.min_int and Na‐
149 tiveint.max_int .
150
151
152 Since 4.14.0
153
154
155
156
157 Advanced functions
158 The functions from module Random.State manipulate the current state of
159 the random generator explicitly. This allows using one or several de‐
160 terministic PRNGs, even in a multi-threaded program, without interfer‐
161 ence from other parts of the program.
162
163 module State : sig end
164
165
166
167
168
169 val get_state : unit -> State.t
170
171
172 get_state() returns a fresh copy of the current state of the domain-lo‐
173 cal generator (which is used by the basic functions).
174
175
176
177 val set_state : State.t -> unit
178
179
180 set_state s updates the current state of the domain-local generator
181 (which is used by the basic functions) by copying the state s into it.
182
183
184
185 val split : unit -> State.t
186
187 Draw a fresh PRNG state from the current state of the domain-local gen‐
188 erator used by the default functions. (The state of the domain-local
189 generator is modified.) See Random.State.split .
190
191
192 Since 5.0.0
193
194
195
196
197
198OCamldoc 2023-07-20 Stdlib.Random(3)