summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/random.ml7
-rw-r--r--stdlib/random.mli9
2 files changed, 9 insertions, 7 deletions
diff --git a/stdlib/random.ml b/stdlib/random.ml
index aa47536ba..50b570822 100644
--- a/stdlib/random.ml
+++ b/stdlib/random.ml
@@ -130,13 +130,12 @@ module State = struct
else fun s bound -> Int64.to_nativeint (int64 s (Int64.of_nativeint bound))
;;
- (* Returns a float 0 <= x < 1 with at most 90 bits of precision. *)
+ (* Returns a float 0 <= x <= 1 with at most 60 bits of precision. *)
let rawfloat s =
- let scale = 1073741824.0
- and r0 = Pervasives.float (bits s)
+ let scale = 1073741824.0 (* 2^30 *)
and r1 = Pervasives.float (bits s)
and r2 = Pervasives.float (bits s)
- in ((r0 /. scale +. r1) /. scale +. r2) /. scale
+ in (r1 /. scale +. r2) /. scale
;;
let float s bound = rawfloat s *. bound;;
diff --git a/stdlib/random.mli b/stdlib/random.mli
index 389ef8d21..9c66c3a86 100644
--- a/stdlib/random.mli
+++ b/stdlib/random.mli
@@ -25,8 +25,11 @@ val full_init : int array -> unit
(** Same as {!Random.init} but takes more data as seed. *)
val self_init : unit -> unit
-(** Initialize the generator with a more-or-less random seed chosen
- in a system-dependent way. *)
+(** Initialize the generator with a random seed chosen
+ in a system-dependent way. If [/dev/urandom] is available on
+ the host machine, it is used to provide a highly random initial
+ seed. Otherwise, a less random seed is computed from system
+ parameters (current time, process IDs). *)
val bits : unit -> int
(** Return 30 random bits in a nonnegative integer.
@@ -53,7 +56,7 @@ val int64 : Int64.t -> Int64.t;;
val float : float -> float
(** [Random.float bound] returns a random floating-point number
- between 0 (inclusive) and [bound] (exclusive). If [bound] is
+ between 0 and [bound] (inclusive). If [bound] is
negative, the result is negative or zero. If [bound] is 0,
the result is 0. *)