From cabc4322f104d34921de80c9379be85daa1fe186 Mon Sep 17 00:00:00 2001 From: Damien Doligez Date: Mon, 31 Mar 1997 15:51:43 +0000 Subject: [PATCH] Meilleure verification de l'argument de Random.int git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1482 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- stdlib/random.ml | 2 +- stdlib/random.mli | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/stdlib/random.ml b/stdlib/random.ml index 7d1528a19..57b687b3d 100644 --- a/stdlib/random.ml +++ b/stdlib/random.ml @@ -53,7 +53,7 @@ let rec intaux n = let r = bits () in if r >= n then intaux n else r let int bound = - if bound > 0x3FFFFFFF + if bound > 0x3FFFFFFF || bound <= 0 then invalid_arg "Random.int" else (intaux (0x3FFFFFFF / bound * bound)) mod bound diff --git a/stdlib/random.mli b/stdlib/random.mli index 24a82fc1d..ea53316f8 100644 --- a/stdlib/random.mli +++ b/stdlib/random.mli @@ -22,9 +22,11 @@ val full_init : int array -> unit val bits : unit -> int (* Return 30 random bits in a nonnegative integer. *) val int : int -> int - (* [Random.int bound] returns a random number between 0 (inclusive) - and [bound] (exclusive). [bound] must be positive and smaller + (* [Random.int bound] returns a random integer between 0 (inclusive) + and [bound] (exclusive). [bound] must be more than 0 and less than $2^{30}$. *) val float : float -> float - (* [Random.float bound] returns a random number between 0 (inclusive) - and [bound] (exclusive). *) + (* [Random.float bound] returns a random floating-point number + between 0 (inclusive) and [bound] (exclusive). If [bound] is + negative, the result is negative. If [bound] is 0, the result + is 0. *)