summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2002-02-01 12:24:44 +0000
committerDamien Doligez <damien.doligez-inria.fr>2002-02-01 12:24:44 +0000
commit67633a84d710a18489a3728b44a8b02e4b077f8a (patch)
treea824651bae33fbdbdc3808a867ca4d2b2f18c91f
parent15c25173cfd956592d37a7a7fe119cb0374437c7 (diff)
ajout Random.bool
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4336 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--stdlib/random.ml5
-rw-r--r--stdlib/random.mli3
2 files changed, 6 insertions, 2 deletions
diff --git a/stdlib/random.ml b/stdlib/random.ml
index 9a65f3149..35d19ff0c 100644
--- a/stdlib/random.ml
+++ b/stdlib/random.ml
@@ -61,8 +61,9 @@ let int bound =
let float bound = rawfloat () *. bound
-(* Simple initialisation. The seed is an integer.
-*)
+let bool () = (bits () land 1 = 0);;
+
+(* Simple initialisation. The seed is an integer. *)
let init seed =
let mdg i =
let d = Digest.string (string_of_int i ^ string_of_int seed) in
diff --git a/stdlib/random.mli b/stdlib/random.mli
index 296a65e0c..32854a659 100644
--- a/stdlib/random.mli
+++ b/stdlib/random.mli
@@ -40,6 +40,9 @@ val float : float -> float
negative, the result is negative. If [bound] is 0, the result
is 0. *)
+val bool : unit -> bool
+(** [Random.bool ()] returns [true] or [false] with probability 0.5 each. *)
+
type state
(** Values of this type are used to store the current state of the
generator. *)