Last active
August 29, 2015 14:04
-
-
Save kharrison/ff34eedb13021f9ef012 to your computer and use it in GitHub Desktop.
Fisher - Yates shuffle Go package
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
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