Hi,

Please let me know if there is another place where I should be asking this.

I want to generate a “shuffled” list or array from let’s say [|1;2;3;4;5|]. I wrote the following code, which works; however, I would like to know if there is a more natural way to do this with OCAML. Please don’t mind the variable names.

```
(* pops a random index, and returns the (value, thelist) *)
let pop_random_value aList =
let n = List.length aList in
let i = Random.int n in
let value = List.nth aList i in
(value, filter_value aList value)
let prepend_value aList aVal = aVal::aList
let get_random_array size =
let n = Array.init size (fun v -> v+1) in
let ni = ref (Array.to_list (Array.init size (fun v -> v))) in
let returnlist = ref [] in
while ((List.length !ni) <> 0) do
let (value, newlist) = pop_random_value !ni in
ni := newlist;
returnlist := prepend_value !returnlist n.(value)
done;
!returnlist
```