Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exception Chosen of string
- (* h : (string, string list) Hashtbl.t *)
- let choose h =
- let tot = Hashtbl.fold (fun _ v s -> s + List.length v) h 0 in
- try
- ignore
- (Hashtbl.fold
- (fun k v r ->
- let len = List.length v in
- let t = r - len in
- if t < 0 then raise (Chosen k)
- else t)
- h
- (Random.int tot));
- assert false (* not reached *)
- with Chosen k ->
- k
Add Comment
Please, Sign In to add comment