let specified_ints prng probabilities =
let len = Array.length probabilities in
let cumul = Array.make len probabilities.(0) in
for i=1 to pred len do cumul.(i) <- cumul.(pred i) +. probabilities.(i) done;
let normalizer = cumul.(pred len) in
if normalizer <> 1. then for i=0 to pred len do cumul.(i) <- cumul.(i) /. normalizer done;
let find sup =
let result = ref 0 in
while !result < pred len && cumul.(!result) < sup do incr result done;
!result in
Array.init len (fun _ -> find (Random.State.float prng 1.))