Created
February 22, 2022 05:47
-
-
Save nidhi-canopas/1900abad8da4e5ec0075cff61ee20993 to your computer and use it in GitHub Desktop.
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
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