I have the following function that works the way I want for a single call:
let shuffle (arr : 'a array) =
let array = Array.copy arr
let rng = new Random()
let n = array.Length
for x in 1..n do
let i = n-x
let j = rng.Next(i+1)
let tmp = array.[i]
array.[i] <- array.[j]
array.[j] <- tmp
array
However, for multiple calls, as in the following (x is not used for anything), it gives the same shuffle for each call. How can I make a shuffle every time?
[for x in 1..3 do yield shuffle [|1;2;3|]]
>
val it : int [] list = [[|1; 3; 2|]; [|1; 3; 2|]; [|1; 3; 2|]]
source
share