Skip to content

Instantly share code, notes, and snippets.

@nidhi-canopas
Created February 22, 2022 05:47
Show Gist options
  • Save nidhi-canopas/1900abad8da4e5ec0075cff61ee20993 to your computer and use it in GitHub Desktop.
Save nidhi-canopas/1900abad8da4e5ec0075cff61ee20993 to your computer and use it in GitHub Desktop.
import "fmt"
func main() {
// shuffle array
array := []string{"India", "US", "Canada", "UK"}
Shuffle(array)
}
func Shuffle(array []string) {
// seed random for changing order of elements
random := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := len(array) - 1; i > 0; i-- {
j := random.Intn(i + 1)
array[i], array[j] = array[j], array[i]
}
fmt.Println("Shuffled array : ", array)
}
output:
Shuffled array : [UK India Canada US]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment