Skip to content

Commit

Permalink
Fixed an error which caused an exception on permuting an empty array
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Minerich <richard.minerich@gmail.com>
  • Loading branch information
Rickasaurus committed Jun 4, 2012
1 parent 685593c commit 960f613
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions AntsEverywhereLib/Helpers.fs
Expand Up @@ -20,16 +20,18 @@ module Array2D =
module Array =
let randomPermute a =
let n = Array.length a
let rand = new Random()
let rec aux = function
| 0 -> a
| k ->
let i = rand.Next(k+1)
let tmp = a.[i]
a.[i] <- a.[k]
a.[k] <- tmp
aux (k-1)
aux (n-1)
if n > 0 then
let rand = new Random()
let rec aux = function
| 0 -> a
| k ->
let i = rand.Next(k+1)
let tmp = a.[i]
a.[i] <- a.[k]
a.[k] <- tmp
aux (k-1)
aux (n-1)
else a

module Seq =
let randomPermute a =
Expand Down

0 comments on commit 960f613

Please sign in to comment.