From f190964cfd95b35d9b6d8b62d4712c90e04d942b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 18 Feb 2019 20:41:17 -0600 Subject: [PATCH] fix: make `Array.random_choose` fail on empty array at creation time see #246 --- src/core/CCArray.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/CCArray.ml b/src/core/CCArray.ml index 3f4b0ec4..2fa87a7d 100644 --- a/src/core/CCArray.ml +++ b/src/core/CCArray.ml @@ -515,10 +515,10 @@ let shuffle_with st a = let rec _to_klist a i j () = if i=j then `Nil else `Cons (a.(i), _to_klist a (i+1) j) -let random_choose a st = +let random_choose a = let n = Array.length a in if n = 0 then raise Not_found; - a.(Random.State.int st n) + fun st -> a.(Random.State.int st n) let random_len n g st = Array.init n (fun _ -> g st)