Simple GoLang Function to Shuffle or Randomize a Slice or Array
If not super often, some time we definitely need to randomize an array or slice. Here's an example implementation to shuffle our array in go programming
Our Shuffle Slice Method
Using rand.shuffle to randomize the order. For referene:
func Shuffle(n int, swap func(i, j int))
Sample output for the function
[8 1 4 2 10 3 7 5 9 6]
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.