I have this bit of code:
let rec random_list = function
| 0 -> []
| n -> ( Random.int max_int ) :: ( random_list (n-1) )
It compiles okay, but when I execute it, this error shows up:
exception Invalid_argument("Random.int")
What is the workaround for this issue ?
The documentation says:
So the closest to what you want is:
As gsg suggested, using
Random.bits ()
is cleaner to get almost the same result (it can also return2^30 - 1
).If you really want to get any positive native integer, maybe you could use
Random.nativeint
, but this means you would have to use the moduleNativeint
andNativeint.t
instead ofint
.