Skip to content

Instantly share code, notes, and snippets.

@g-dormoy
Created October 20, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-dormoy/fef174d87e0f52b8eb36 to your computer and use it in GitHub Desktop.
Save g-dormoy/fef174d87e0f52b8eb36 to your computer and use it in GitHub Desktop.
package main
import "fmt"
import "math/rand"
func shuffleSlice(slice []interface{}) []interface{} {
for i := range slice {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
return slice
}
func main() {
list := make([]interface{}, 4)
list[0] = "foo"
list[1] = "bar"
list[2] = "foo1"
list[3] = "bar1"
list = shuffleSlice(list)
fmt.Println(list...)
list = shuffleSlice(list)
fmt.Println(list...)
list = shuffleSlice(list)
fmt.Println(list...)
list = shuffleSlice(list)
fmt.Println(list...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment