Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created April 30, 2014 16:21
Show Gist options
  • Save kristopherjohnson/aab3b42911e25c3ec352 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/aab3b42911e25c3ec352 to your computer and use it in GitHub Desktop.
F# array shuffle
let shuffleInPlace (array : 'a[]) =
let swap i j =
let temp = array.[i]
array.[i] <- array.[j]
array.[j] <- temp
let random = new Random()
let len = array.Length
[0..len-2] |> Seq.iter(fun i -> swap i (random.Next(i, len)))
array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment