Skip to content

Instantly share code, notes, and snippets.

@kharrison
Last active August 29, 2015 14:04
Show Gist options
  • Save kharrison/ff34eedb13021f9ef012 to your computer and use it in GitHub Desktop.
Save kharrison/ff34eedb13021f9ef012 to your computer and use it in GitHub Desktop.
Fisher - Yates shuffle Go package
package shuffle
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// Fisher - Yates shuffle
func FYShuffle(deck []int) {
for j := len(deck) - 1; j > 0; j-- {
k := rand.Intn(j + 1)
deck[j], deck[k] = deck[k], deck[j]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment