Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 531

What is wrong with this code for creating lists in OCaml?

$
0
0

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?


Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>