I am trying to create a program in OCaml [randlist len max], which would generate an int list of length len with integers smaller than max.
I am wondering what is wrong with the following code:
let randlist dolzina maksimum = let rec aux dolz maks acc = match (List.length acc) with | dolz -> acc | _ -> aux dolz maks ((Random.int maks) :: acc) in aux dolzina maksimum []
This always returns an empty list and I do not understand why.
Another thing that confuses me is what goes wrong with the following code:
let randlist dolzina maksimum = Random.self_init () let rec aux dolz maks acc = match (List.length acc) with | dolz -> acc | _ -> aux dolz maks ((Random.int maks) :: acc) in aux dolzina maksimum []
As soon as I add the Random.self init () the whole code crashes. What exactly does Random.self_init do, when and how do I use it?