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 generator, using the argument as a seed. The same seed
27 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 generator with a random seed chosen in a system-depen‐
40 dent way. If /dev/urandom is available on the host machine, it is used
41 to provide a highly random initial seed. Otherwise, a less random seed
42 is computed from system parameters (current time, process IDs).
43
44
45
46 val bits : unit -> int
47
48 Return 30 random bits in a nonnegative integer.
49
50
51 Before3.12.0 used a different algorithm (affects all the following
52 functions)
53
54
55
56
57 val int : int -> int
58
59
60 Random.int bound returns a random integer between 0 (inclusive) and
61 bound (exclusive). bound must be greater than 0 and less than 2^30.
62
63
64
65 val full_int : int -> int
66
67
68 Random.full_int bound returns a random integer between 0 (inclusive)
69 and bound (exclusive). bound may be any positive integer.
70
71 If bound is less than 2^30, Random.full_int bound is equal to Ran‐
72 dom.int bound . If bound is greater than 2^30 (on 64-bit systems or
73 non-standard environments, such as JavaScript), Random.full_int returns
74 a value, where Random.int raises Invalid_argument .
75
76
77 Since 4.13.0
78
79
80
81 val int32 : Int32.t -> Int32.t
82
83
84 Random.int32 bound returns a random integer between 0 (inclusive) and
85 bound (exclusive). bound must be greater than 0.
86
87
88
89 val nativeint : Nativeint.t -> Nativeint.t
90
91
92 Random.nativeint bound returns a random integer between 0 (inclusive)
93 and bound (exclusive). bound must be greater than 0.
94
95
96
97 val int64 : Int64.t -> Int64.t
98
99
100 Random.int64 bound returns a random integer between 0 (inclusive) and
101 bound (exclusive). bound must be greater than 0.
102
103
104
105 val float : float -> float
106
107
108 Random.float bound returns a random floating-point number between 0 and
109 bound (inclusive). If bound is negative, the result is negative or
110 zero. If bound is 0, the result is 0.
111
112
113
114 val bool : unit -> bool
115
116
117 Random.bool () returns true or false with probability 0.5 each.
118
119
120
121
122 Advanced functions
123 The functions from module Random.State manipulate the current state of
124 the random generator explicitly. This allows using one or several de‐
125 terministic PRNGs, even in a multi-threaded program, without interfer‐
126 ence from other parts of the program.
127
128 module State : sig end
129
130
131
132
133
134 val get_state : unit -> State.t
135
136 Return the current state of the generator used by the basic functions.
137
138
139
140 val set_state : State.t -> unit
141
142 Set the state of the generator used by the basic functions.
143
144
145
146
147
148OCamldoc 2022-02-04 Stdlib.Random(3)