Created
April 30, 2014 16:21
-
-
Save kristopherjohnson/aab3b42911e25c3ec352 to your computer and use it in GitHub Desktop.
F# array shuffle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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