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
19
20
21
22
23
24   Basic functions
25       val init : int -> unit
26
27       Initialize  the generator, using the argument as a seed.  The same seed
28       will always yield the same sequence of numbers.
29
30
31
32       val full_init : int array -> unit
33
34       Same as Random.init but takes more data as seed.
35
36
37
38       val self_init : unit -> unit
39
40       Initialize the generator with a random seed chosen in  a  system-depen‐
41       dent way.  If /dev/urandom is available on the host machine, it is used
42       to provide a highly random initial seed.  Otherwise, a less random seed
43       is computed from system parameters (current time, process IDs).
44
45
46
47       val bits : unit -> int
48
49       Return 30 random bits in a nonnegative integer.
50
51
52       Before3.12.0  used  a  different  algorithm  (affects all the following
53       functions)
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
123   Advanced functions
124       The functions from module Random.State manipulate the current state  of
125       the  random generator explicitly.  This allows using one or several de‐
126       terministic PRNGs, even in a multi-threaded program, without  interfer‐
127       ence from other parts of the program.
128
129       module State : sig end
130
131
132
133
134
135       val get_state : unit -> State.t
136
137       Return the current state of the generator used by the basic functions.
138
139
140
141       val set_state : State.t -> unit
142
143       Set the state of the generator used by the basic functions.
144
145
146
147
148
149OCamldoc                          2022-02-04                         Random(3)
Impressum