1Random(3)                        OCaml library                       Random(3)
2
3
4

NAME

6       Random - Pseudo-random number generators (PRNG).
7

Module

9       Module   Random
10

Documentation

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