Jump to content

Pick random element: Difference between revisions

(→‎{{header|Euphoria}}: Euphoria example added)
Line 78:
 
=={{header|OCaml}}==
With a list:
<lang ocaml>let list_rand lst =
let len = List.length lst in
Line 84 ⟶ 85:
<pre>
# list_rand [1;2;3;4;5] ;;
- : int = 3
</pre>
 
With an array:
<lang ocaml>let array_rand ary =
let len = Array.length ary in
ary.(Random.int len)</lang>
 
<pre>
# array_rand [|1;2;3;4;5|] ;;
- : int = 3
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.