mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
fix: make Array.random_choose fail on empty array at creation time
see #246
This commit is contained in:
parent
c893716c1a
commit
f190964cfd
1 changed files with 2 additions and 2 deletions
|
|
@ -515,10 +515,10 @@ let shuffle_with st a =
|
||||||
let rec _to_klist a i j () =
|
let rec _to_klist a i j () =
|
||||||
if i=j then `Nil else `Cons (a.(i), _to_klist a (i+1) 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
|
let n = Array.length a in
|
||||||
if n = 0 then raise Not_found;
|
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 =
|
let random_len n g st =
|
||||||
Array.init n (fun _ -> g st)
|
Array.init n (fun _ -> g st)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue