Meilleure verification de l'argument de Random.int

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1482 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 1997-03-31 15:51:43 +00:00
parent 08afd50270
commit cabc4322f1
2 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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. *)